Created
January 17, 2017 19:28
-
-
Save JakeDEvans/3d566ce5bac924a73c377a3b31ed9679 to your computer and use it in GitHub Desktop.
nxos vlan playbook with nested, conditional loop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: localhost | |
gather_facts: False | |
vars: | |
switches: | |
- hostname: switch01.example.com | |
- hostname: switch02.example.com | |
subnets: | |
general_use: | |
subnet: 10.0.0.0/16 | |
specific_use: | |
subnet: 10.1.0.0/24 | |
vlan: 100 | |
vars_prompt: | |
- name: "cisco_username" | |
prompt: "Username" | |
- name: "cisco_password" | |
prompt: "Password" | |
private: yes | |
tasks: | |
- name: vLAN | |
nxos_vlan: | |
vlan_id: "{{ subnets[item[1]]['vlan'] }}" | |
name: "{{ item[1] }}" | |
host: "{{ item[0]['hostname'] }}" | |
username: "{{ cisco_username }}" | |
password: "{{ cisco_password }}" | |
transport: nxapi | |
use_ssl: yes | |
with_nested: | |
- "{{ switches}}" | |
- "{{ subnets }}" | |
when: "{{ subnets[item[1]]['vlan'] | default('skip') != 'skip' }}" | |
delegate_to: 127.0.0.1 |
I'd try without SSL just curious if that speeds things up.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Either way, you should have switches in the inventory file. It's good practice.