我有一个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