In my AWX Tower, I have globally set up a proxy. I recently encountered a situation where I needed an exception for a specific task. This can be done as follows: In the task, the variables http_proxy and no_proxy can be set under the variable environment. These will then apply only to that specific task.
environment:
no_proxy: 10.10.10.1,www.example.com
http_proxy: http://proxy.homelab.local:8080
Here is a complete example: I use ios_command to retrieve all ports that use PoE and have “Phone” in the description. I then send the output to my Flask micro web service for further use.
- hosts: all
tasks:
- name: Get phones
ios_command:
commands:
- show power inline | inc Phone
register: phones
- name: Send results to micro webservice
uri:
url: http://10.10.10.1/datadrop/
method: POST
user: awx_datadrop
password: geheim
body: |
{'hostname': '{{ inventory_hostname }}',
'module': 'phone_collector',
'results': {
'power': {{ phones.stdout_lines[0] }},
}
status_code: 200
body_format: json
environment:
no_proxy: 10.10.10.1