Skip to content

Instantly share code, notes, and snippets.

@JakeDEvans
Created January 17, 2017 19:28
Show Gist options
  • Save JakeDEvans/3d566ce5bac924a73c377a3b31ed9679 to your computer and use it in GitHub Desktop.
Save JakeDEvans/3d566ce5bac924a73c377a3b31ed9679 to your computer and use it in GitHub Desktop.
nxos vlan playbook with nested, conditional loop.
- 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
@jedelman8
Copy link

Either way, you should have switches in the inventory file. It's good practice.

@jedelman8
Copy link

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