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
Depending on the hardware model, this playbook will copy the appropriate image from an HTTP web server to the switch.
Ansible: Parse Cisco commando ouputs with TEXTFSM
·390 words·2 mins
netdevops blog cisco textfsm ansible
To parse outputs of commands in Ansible you can use TEXTFSM.
Reboot Accesspoints with Ansible
·160 words·1 min
netdevops blog ansible cisco
Sometimes it is necessary to reboot the accesspoints and if you don`t want to do it by hand let Ansible work for you :-)