03-28-2023 05:34 PM
I have an extended access list and for simplicity sake I will say it is lines 1 to 10. I want to add lines 11 to 15 to the existing extended ACL using the ios_acl module for Ansible. I need to be able to loop through each acl I have in the playbook so that each rule will be appended to the end of the list of ACLs. Here is my playbook but since I am still learning, I am at a loss as to the simplest way to accomplish my task.
Solved! Go to Solution.
03-28-2023 11:57 PM - edited 03-29-2023 12:19 AM
Hi David
If you want to add addional entries to the ACL I think you can do it without a loop, just align the dicts in your "acl_rules" variable to the schema of the dict used in the Ansible module (https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_acls_module.html):
- name: Merge Access Lists
hosts: Router
gather_facts: false
vars:
acl_name: pos-to-wan
acl_rules:
- sequence: 911
grant: permit
source:
any: true
destination:
host: 198.22.203.230
port_protocol:
eq: 443
protocol: tcp
- sequence: 912
grant: permit
source:
any: true
destination:
host: 209.236.103.70
port_protocol:
eq: 443
protocol: tcp
- sequence: 913
grant: permit
source:
any: true
destination:
host: 198.22.206.247
port_protocol:
eq: 22
protocol: tcp
tasks:
- name: Merge Access List Rules
cisco.ios.ios_acls:
config:
- afi: ipv4
acls:
- name: "{{ acl_name }}"
acl_type: extended
aces: "{{ acl_rules }}"
HTH
Marcel
03-28-2023 11:57 PM - edited 03-29-2023 12:19 AM
Hi David
If you want to add addional entries to the ACL I think you can do it without a loop, just align the dicts in your "acl_rules" variable to the schema of the dict used in the Ansible module (https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_acls_module.html):
- name: Merge Access Lists
hosts: Router
gather_facts: false
vars:
acl_name: pos-to-wan
acl_rules:
- sequence: 911
grant: permit
source:
any: true
destination:
host: 198.22.203.230
port_protocol:
eq: 443
protocol: tcp
- sequence: 912
grant: permit
source:
any: true
destination:
host: 209.236.103.70
port_protocol:
eq: 443
protocol: tcp
- sequence: 913
grant: permit
source:
any: true
destination:
host: 198.22.206.247
port_protocol:
eq: 22
protocol: tcp
tasks:
- name: Merge Access List Rules
cisco.ios.ios_acls:
config:
- afi: ipv4
acls:
- name: "{{ acl_name }}"
acl_type: extended
aces: "{{ acl_rules }}"
HTH
Marcel
03-29-2023 07:31 AM
Thanks for all your help. With a few changes, I was able to accomplish the task that I was after. Here is my revised file:
08-16-2024 09:44 AM
This is not idempotent (always reports changed status) for me, was it for you guys?
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide