-
Notifications
You must be signed in to change notification settings - Fork 4
/
02_setup_interfaces.yml
77 lines (71 loc) · 2.77 KB
/
02_setup_interfaces.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
- name: "PLAY 1: ADD INTERFACES TO NAUTOBOT AND CLEANUP TEMP"
connection: ansible.netcommon.network_cli
hosts: platforms_nxos, platforms_ios, platforms_eos
vars:
ssl_verify: True
tags: [ios, nxos]
tasks:
- name: "TASK 1A: NXOS >> GET NXOS FACTS"
when: "ansible_network_os == 'nxos'"
nxos_facts:
gather_subset: "!config"
- name: "TASK 1B: IOS >> GET IOS FACTS"
when: "ansible_network_os == 'ios'"
ios_facts:
gather_subset: "!config"
- name: "TASK 1C: EOS >> GATHER FACTS FROM DEVICE"
when: "ansible_network_os == 'eos'"
eos_facts:
gather_subset: "!config"
- name: "TASK 2: NAUTOBOT >> ADD INTERFACES TO NAUTOBOT"
networktocode.nautobot.device_interface:
url: "{{ lookup('env', 'NAUTOBOT_URL') }}"
token: "{{ lookup('env', 'NAUTOBOT_TOKEN') }}"
device: "{{ inventory_hostname }}"
name: "{{ item.key }}"
type: "{{ item.key | get_interface_type }}"
mac_address: "{{ item.value.macaddress | convert_mac_address }}"
state: present
validate_certs: "{{ ssl_verify }}"
with_dict:
- "{{ ansible_facts['net_interfaces'] }}"
loop_control:
label: "{{ item.key }}"
- name: "TASK 3: NAUTOBOT >> ADD IP ADDRESSES TO PROPER INTERFACE"
networktocode.nautobot.ip_address:
url: "{{ lookup('env', 'NAUTOBOT_URL') }}"
token: "{{ lookup('env', 'NAUTOBOT_TOKEN') }}"
family: 4
address: "{{ item['address'] }}"
status: active
assigned_object:
name: "{{ item['interface'] }}"
device: "{{ inventory_hostname }}"
validate_certs: "{{ ssl_verify }}"
with_items:
- "{{ ansible_facts | build_ipv4_from_facts }}"
- name: "TASK 4: NAUTOBOT >> REMOVE TEMPORARY INTERFACE"
networktocode.nautobot.device_interface:
url: "{{ lookup('env', 'NAUTOBOT_URL') }}"
token: "{{ lookup('env', 'NAUTOBOT_TOKEN') }}"
device: "{{ inventory_hostname }}"
name: Temporary_Interface
type: Virtual
validate_certs: "{{ ssl_verify }}"
state: absent
- name: "TASK 5: NAUTOBOT >> SET PRIMARY IP"
networktocode.nautobot.device:
url: "{{ lookup('env', 'NAUTOBOT_URL') }}"
token: "{{ lookup('env', 'NAUTOBOT_TOKEN') }}"
validate_certs: "{{ ssl_verify }}"
name: "{{ inventory_hostname }}"
device_type: "{{ ansible_facts['net_model'] }}"
serial: "{{ ansible_facts['net_serialnum'] }}"
rack: MN_01
device_role: "{{ inventory_hostname | get_role_from_hostname }}"
primary_ip4: "{{ item['address'] }}"
status: "Active"
with_items:
- "{{ ansible_facts | build_ipv4_from_facts }}"
when: "ansible_host == item['address'].split('/')[0]"