Skip to content

Instantly share code, notes, and snippets.

@adosztal
Last active October 5, 2016 17:54
Show Gist options
  • Save adosztal/47d5589bcda11396a9e6e218e6e21b3f to your computer and use it in GitHub Desktop.
Save adosztal/47d5589bcda11396a9e6e218e6e21b3f to your computer and use it in GitHub Desktop.
Ansible task running twice
###
### Main YAML file
###
- hosts: leaf_switches <<< note: this group has two elements, nx3 and nx4
connection: local
roles:
- configure_access_ports
###
### vars/main.yaml
###
---
# host (switch name), interface, description, mode (access/trunk), vlan_id (native vlan for trunk), allowed_vlans (trunks only), speed, duplex, state (admin state up/down)
port_list:
- { host: "nx3", interface: "Ethernet2/5", description: "server1_eth0", mode: access, vlan_id: "199", speed: "auto", duplex: "auto", state: "up" }
- { host: "nx4", interface: "Ethernet2/5", description: "server1_eth1", mode: access, vlan_id: "199", speed: "auto", duplex: "auto", state: "up" }
###
### tasks/main.yaml
###
---
- name: Configuring physical interface properties
nxos_interface:
host="{{ item.host }}"
username="{{ username }}"
password="{{ password }}"
transport=nxapi
interface="{{ item.interface }}"
description="{{ item.description }}"
mode=layer2
admin_state="down"
with_items: "{{ port_list }}"
[...]
###
### Output
###
TASK [configure_access_ports : Configuring physical interface properties] ******
changed: [localhost] => (item={u'description': u'server1_eth0', u'duplex': u'auto', u'host': u'nx3', u'state': u'up', u'mode': u'access', u'interface': u'Ethernet2/5', u'speed': u'auto', u'vlan_id': u'199'})
changed: [localhost] => (item={u'description': u'server1_eth1', u'duplex': u'auto', u'host': u'nx4', u'state': u'up', u'mode': u'access', u'interface': u'Ethernet2/5', u'speed': u'auto', u'vlan_id': u'199'})
ok: [localhost] => (item={u'description': u'server2_eth0', u'duplex': u'full', u'host': u'nx3', u'state': u'down', u'mode': u'trunk', u'interface': u'Ethernet2/6', u'allowed_vlans': u'180,199', u'speed': u'1000', u'vlan_id': u'1'})
changed: [localhost] => (item={u'description': u'server3_eth0', u'duplex': u'auto', u'host': u'nx4', u'state': u'up', u'mode': u'access', u'interface': u'Ethernet2/7', u'speed': u'auto', u'vlan_id': u'199'})
changed: [localhost] => (item={u'description': u'server3_eth1', u'duplex': u'auto', u'host': u'nx3', u'state': u'up', u'mode': u'access', u'interface': u'Ethernet2/7', u'speed': u'auto', u'vlan_id': u'199'})
ok: [localhost] => (item={u'description': u'server4_eth0', u'duplex': u'full', u'host': u'nx3', u'state': u'down', u'mode': u'trunk', u'interface': u'Ethernet2/8', u'allowed_vlans': u'180,199', u'speed': u'1000', u'vlan_id': u'1'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment