how do I use ios_config to change configuration to default?

33 views
Skip to first unread message

John Z

unread,
Apr 26, 2017, 9:09:48 AM4/26/17
to Ansible Project
How do I use ios_config to delete configuration but only if it is present? I want ios_config to update many devices to conform to a standard template. It will have to delete configuration as well as add it.   I don't want ios_config to update a device or increment the change counter if a device is already configured correctly. 

Its pretty easy to handle adding or modifying ACLs. For example the following task will modify the acl only if it is different or not present:
  - name:configure acl
    ios_config:
      parents: ip access-list extended jhz-test
      lines:
        - permit ip host 1.1.1.1 any log
        - permit ip host 2.2.2.2 any log
        - permit ip host 3.3.3.3 any log
        - permit ip host 4.4.4.4 any log
        - permit ip host 5.5.5.5 any log
      before: no ip access-list extended jhz-test
      match: exact
      replace: block
      provider: "{{ creds }}"
      authorize: True
 
The obvious way to delete configuration is with a "no" command and match = None, but that reconfigures the device and increments the change counter even if the device is already configured correctly.  I have tried a couple of other things, but nothing works. 
  - name: clear acl if present
    ios_config:
      lines:
        - no ip access-list extended jhz-test
      match: non
      provider: "{{ creds }}"
      authorize: True
 



Rama Krishna

unread,
May 8, 2017, 7:14:40 AM5/8/17
to Ansible Project
Use Jinja2 template with ios_config, and set the module parameter match: line, which will do the job as you seek.

cheers
Reply all
Reply to author
Forward
0 new messages