我有一個python腳本,它利用Ansible ad hoc命令快速獲取主機信息。我想抑制時,我試圖收集有關主機處於不同的VPC信息的警告,但顯示了用於查找所有實例以下命令:抑制Ansible Ad Hoc警告
aws ec2 describe-instances
下面是Python代碼段我使用的是製造和產生ansible特設命令:
command_string = "ansible -i /repo/ansible/inventory/"+env+"/hosts " + name + " -m shell -a 'df -h'"
result = subprocess.Popen(command_string, shell=True, stdout=subprocess.PIPE).stdout.read()
據我所知,在劇本設置的外殼模塊:
warn=no
將禁用警告,但我似乎無法弄清楚如何通過即席這樣做,請參見下面的測試:
[[email protected] 10.0.5.xxx:~] ansible -i /repo/ansible/inventory/nqa/hosts 10.19.1.17 -m shell -a 'warn=no'
[WARNING]: No hosts matched, nothing to do
[[email protected] 10.0.5.xxx:~] ansible -i /repo/ansible/inventory/nqa/hosts 10.19.1.17 -m shell -a 'warn=false'
[WARNING]: No hosts matched, nothing to do
我完整的腳本的輸出類似於以下內容:
i-xxxxxx
my-super-cool-box
t2.small True
10.0.0.10
vol-xxxxxxx
100
i-xxxxxxx
/dev/xvdf
[WARNING]: No hosts matched, nothing to do
[WARNING]: No hosts matched, nothing to do
[WARNING]: No hosts matched, nothing to do
印刷有關的信息特定的實例是正確的,我所需要的是一種在不改變全局可靠配置的情況下抑制該警告的方法。
思考使用http:/ /docs.ansible.com/ansible/intro_dynamic_inventory.html#example-aws-ec2-external-inventory-script – BMW