【发布时间】:2017-10-03 02:45:12
【问题描述】:
我有一个 python 脚本,它利用 Ansible ad hoc 命令快速获取主机信息。当我尝试收集有关位于不同 VPC 中的主机的信息时,我想禁止显示警告,但在以下用于查找所有实例的命令中显示:
aws ec2 describe-instances
下面是我用来制作和生成 ansible ad hoc 命令的 python sn-p:
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()
我了解在 shell 模块的剧本设置中:
warn=no
将禁用警告,但我似乎无法弄清楚如何通过 adhoc 这样做,请参阅下面的测试:
[root@box-1b 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
[root@box-1b 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
打印的关于特定实例的信息是正确的,我正在寻找一种在不更改全局 ansible 配置的情况下抑制该警告的方法。
【问题讨论】:
标签: python amazon-web-services ansible