I am a bit new to ansible, I am ok at making playbooks on static devices.  
What I would like to do is make a playbook that is sort of universal.  I 
would like to add a vlan to a cisco switch then automatically add it to all 
the trunk ports.  First what I am trying is to add vlans to all the trunk 
ports.  I am not sure if I am doing this correctly.  I want to loop all the 
l2_interfaces that are set to trunk and add the vlans on the switch to them 
as allowed vlans.  I think this script is working off of a predetermined 
list of vlans and ports.

  hosts: all
  connection: network_cli
  gather_facts: no
  vars:
     ansible_network_os: ios

  tasks:

    - name: Get config for IOS devices
      ios_facts:
        gather_subset:
          - '!all'
          - '!min'
        gather_network_resources:
          - 'l2_interfaces'

    - name: Configure L2 Trunks
      ios_l2_interfaces:
          name: "{{ item.name }}"
          mode: "{{ item.mode }}"
          trunk_allowed_vlans: "{{ vlans | map(attribute='vlan_id') | join(',') 
}}"
          state: present
      loop: "{{ l2_interfaces[ansible_net_hostname] | 
selectattr('mode','equalto','trunk') | list}}"

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c7432c33-8e8d-403c-8640-7a54f625563fn%40googlegroups.com.

Reply via email to