Suppress Ansible Ad Hoc Warning

amazon-web-services, ansible, python

Solution

This is worked for me `ANSIBLE_PYTHON_INTERPRETER=auto_silent`

example: `ANSIBLE_PYTHON_INTERPRETER=auto_silent ansible -i /repo/ansible/inventory/nqa/hosts 10.19.1.17 -m shell -a "uptime"`

Problem

I have a python script that takes advantage of an Ansible ad hoc command to get host information quickly. I'd like to suppress the warning when I'm attempting to gather information about a host that is in a different VPC, but shows in the following command used to find all instances: ``` aws ec2 describe-instances ``` Below is the python snippet I'm using to make and generate the ansible ad hoc command: ``` 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() ``` I understand that in a playbook setting for the shell module: ``` warn=no ``` will disable warnings, but I can't seem to figure out how to do so via adhoc, see below test: ``` [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 ``` The output of my full script looks similar to the following: ``` 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 ``` The information printed about the specific instance is correct, and all I'm looking for is a way to suppress that warning without changing the global ansible configurations.

Original source