Skip to main content
  1. Posts/

Ansible: Disable / Enable proxy for single task

·152 words·1 min·
Netdevops Blog Ansible Proxy Tower
Maximilian Thoma
Author
Maximilian Thoma
network engineer

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

Related

Rollout new images to Cisco devices with Ansible
·307 words·2 mins
Netdevops Blog Ansible Cisco Rollout Update
Ansible: Parse Cisco commando ouputs with TEXTFSM
·390 words·2 mins
Netdevops Blog Cisco Textfsm Ansible
Reboot Accesspoints with Ansible
·160 words·1 min
Netdevops Blog Ansible Cisco