Created
March 22, 2016 19:44
-
-
Save packetninja/50daabd3a223feff6713 to your computer and use it in GitHub Desktop.
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
vagrant@oob-mgmt-server:~/tenict/ansible$ cat interfaces.yml | |
--- | |
- hosts: switches | |
user: root | |
tasks: | |
- name: configure /etc/network/interfaces | |
template: src=templates/interfaces.j2 dest=/etc/network/interfaces | |
notify: restart networking | |
- name: ensure networking is running | |
service: name=networking state=started | |
handlers: | |
- name: restart networking | |
command: "/sbin/ifreload -a" | |
vagrant@oob-mgmt-server:~/tenict/ansible$ cat group_vars/all | |
interfaces: | |
leaf01: | |
int_unassigned: ["swp1", "swp2", "swp49", "swp50", "swp51", "swp52"] | |
loopback: | |
ip: "10.100.1.1" | |
leaf02: | |
int_unassigned: ["swp1", "swp2", "swp49", "swp50", "swp51", "swp52"] | |
loopback: | |
ip: "10.100.1.2" | |
leaf03: | |
int_unassigned: ["swp1", "swp2", "swp49", "swp50", "swp51", "swp52"] | |
loopback: | |
ip: "10.100.1.3" | |
leaf04: | |
int_unassigned: ["swp1", "swp2", "swp49", "swp50", "swp51", "swp52"] | |
loopback: | |
ip: "10.100.1.4" | |
vagrant@oob-mgmt-server:~/tenict/ansible$ cat templates/interfaces.j2 | |
{{ header_tmpl }} | |
{%- set intvars = interfaces[ansible_hostname] -%} | |
{%- set loopback_int = intvars.loopback -%} | |
# Default Loopback | |
auto lo | |
iface lo inet loopback | |
{% if loopback_int is defined -%} | |
# Generated Loopback | |
auto lo:1 | |
iface lo:1 inet static | |
address {{ loopback_int[ip] }}/32 | |
{% endif -%} | |
# Vagrant interface | |
auto vagrant | |
iface vagrant inet dhcp | |
# Management interface | |
auto eth0 | |
iface eth0 inet dhcp | |
# | |
# SWP | |
# | |
{% if intvars.int_unassigned is defined -%} | |
{% for intname in intvars.int_unassigned %} | |
auto {{ intname }} | |
iface {{ intname }} | |
{% endif -%} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment