Ansible to Configure DHCP IP-Helper Address on Multiple Devices

In this post we'll be configuring ip-helper address on multiple devices using Ansible. We'll be defining the interfaces to be configured for different devices in host_vars.

In ansible, host-specific variables can be defined in the host_vars sub-directory either in the home directory of user executing ansible play or in /etc/ansible. Each file/directory in the host_vars sub-directory is name after the host it represents, e.g. host variable for device router-01 are stored in either ~/host_vars/router-01 or /etc/ansible/host_vars/router-01

Define variables for different interfaces of various devices that would be configured by Ansible play.

$ mkdir host_vars

$ vi host_vars/ios-xe-01.yml
  - interface: loopback 30

$ vi host_vars/ios-xe-02.yml
  - interface: loopback 25
  - interface: loopback 35

Let's view the roles in tree view

$ tree host_vars/
├── ios-xe-01.yml
└── ios-xe-02.yml
0 directories, 2 files 

Create inventory file

$ vi inv_cisco-router 
# Asible Inventory file for cisco XE routers



Create playbook for configuring ip-helper address

$ vi play_helper-addr.yml
- name: Configure ip-helper on multiple devices
  hosts: all
  gather_facts: no
  connection: network_cli
    - ios_config:
          - ip helper-address
          - ip helper-address
        parents: interface {{ item.interface }}
      with_items: "{{ dhcp_interfaces }}" 

Let's run the playbook

$ ansible-playbook play_helper-addr.yml -i inv_cisco-router
PLAY [Configure ip-helper on multiple devices] *******************************************************************************************
TASK [ios_config] ************************************************************************************************************************
changed: [ios-xe-01] => (item={'interface': 'loopback 25'})
changed: [ios-xe-02] => (item={'interface': 'loopback 35'})
changed: [ios-xe-02] => (item={'interface': 'loopback 30'})
PLAY RECAP ******************************************************************************************************************************* : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0      : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0


Let's verify the IP helper address on devices
ios-xe-01#show ip helper-address 
Interface                  Helper-Address  VPN     VRG Name        VRG State
Loopback30          0       None            Unknown
                    0       None            Unknown
ios-xe-02#show ip helper-address 
Interface                  Helper-Address  VPN     VRG Name        VRG State
Loopback25          0       None            Unknown
                    0       None            Unknown
Loopback35          0       None            Unknown
                    0       None            Unknown


Popular posts from this blog

Anyconnect SSL-Client VPN with Self-signed Certificate on Cisco ASA

Filtering Routes in BGP using Route-maps and Prefix-list

Open Shortest Path First (OSPF)

IKEv2 IPsec Site-to-Site VPN configuration on Cisco ASA 8.4(x)

IPsec VPN as a Backup for Point-to-Point Link using IP SLA

Border Gateway Protocol (BGP)

Bypassing Proxy Server in Google Chrome

Cisco ASA Active/Active Failover Configuration

Cisco ASA Active/Standby Failover Configuration