我有一个python脚本,它利用Ansible ad hoc命令快速获取主机信息。当我尝试收集有关不同VPC中的主机的信息时,我想要取消警告,但在以下用于查找所有实例的命令中显示:
aws ec2 describe-instances
下面是我用来制作和生成ansible ad hoc命令的python片段:
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模块的playbook设置中:
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
关于特定实例打印的信息是正确的,我正在寻找的是一种在不改变全局安全配置的情况下抑制该警告的方法。
答案 0 :(得分:1)
此警告与warn: no
/ adhoc
模块警告没有任何共同之处,您可以使用10.19.1.17
控制这些警告。
当您提供的主机模式与您的广告资源中的任何主机不匹配时,/repo/ansible/inventory/nqa/hosts
CLI会打印此警告。
在您的示例中,主机class Base
{
public:
// made it pure virtual to decrease clutter
virtual void fnc(int nm) =0;
void process()
{
for(int i = 0; i < 1000; i++)
{
fnc(i);
}
}
};
void test(Base* b ) {
return b->process();
}
未在test(Base*):
push rbp ; setup function call
push rbx
mov rbp, rdi ; Base* rbp
xor ebx, ebx ; int ebx=0;
sub rsp, 8 ; advance stack ptr
.L2:
mov rax, QWORD PTR [rbp+0] ; read 8 bytes from our Base*
; rax now contains vtable ptr
mov esi, ebx ; int parameter for fnc
add ebx, 1 ; i++
mov rdi, rbp ; (Base*) this parameter for fnc
call [QWORD PTR [rax]] ; read vtable and call fnc
cmp ebx, 1000 ; back to the top of the loop
jne .L2
add rsp, 8 ; reset stack ptr and return
pop rbx
pop rbp
ret
广告资源中定义,因此Ansible会向您发出警告,说明无所事事。
确保您使用静态清单文件中存在的主机运行Ansible,或者设置ec2 dynamic inventory并针对所有EC2实例运行Ansible或按标记,security_group等过滤
。答案 1 :(得分:1)
这对我有用ANSIBLE_PYTHON_INTERPRETER=auto_silent
示例:ANSIBLE_PYTHON_INTERPRETER=auto_silent ansible -i /repo/ansible/inventory/nqa/hosts 10.19.1.17 -m shell -a "uptime"
答案 2 :(得分:0)
将环境变量ANSIBLE_DEPRECATION_WARNINGS
设置为false
,如下所示:
ANSIBLE_DEPRECATION_WARNINGS=false ansible -i /path/to/inventory hosts -a your_command
答案 3 :(得分:0)
ANSIBLE_COMMAND_WARNINGS=false ansible ...
ANSIBLE_COMMAND_WARNINGS=no ansible ...