-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmanage_aci_dhcp.yml
77 lines (70 loc) · 2.49 KB
/
manage_aci_dhcp.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
#!/usr/bin/ansible-playbook
---
#
# Copyright (c) 2019 World Wide Technology, Inc.
# All rights reserved.
#
# author: Joel W. King, World Wide Technology
#
# usage: ./manage_aci_dhcp.yml -e "sheet='DHCP Relay' data_center=DC1 ticket=CHG12345"
#
# description: Sample playbook to illustrate using an Excel file as input to ACI configuration
#
# ------
# Play 1
# ------
- hosts: localhost
gather_facts: no
connection: local
tags: [play1]
vars:
# defaults, override with --extra-vars
spreadsheet: '{{ playbook_dir }}/files/aci/ACI_DHCP_configuration.xlsx'
sheet: 'DHCP Relay' # Name of the sheet in the spreadsheet file
dest: '{{ playbook_dir }}/files/aci/' # Location where files are stored
tasks:
- name: Extract the sheets from the Excel file, creating CSV file(s)
xls_to_csv:
src: '{{ spreadsheet }}'
dest: '{{ dest }}'
sheets:
- '{{ sheet }}'
warn: True
# ------
# Play 2
# ------
- hosts: APIC
gather_facts: no
connection: local
tags: [play2]
vars:
# defaults, override with --extra-vars
bootstrap: aci_dhcp.yml
desired_state: present # To delete, specify 'absent'
data_center: DC1 # Only configure one data center at a time
ticket: 'change request ticket number' # Add a 'ticket' or reference number to the config
src: '{{ playbook_dir }}/files/aci/' # Location where files are stored
sheet: 'DHCPRelay' # Name of the sheet in the spreadsheet file
vars_files:
- '{{ playbook_dir }}/files/{{ bootstrap }}'
tasks:
- name: Summarize the sheet and include as facts
csv_to_facts:
src: '{{ src }}/{{ sheet }}.csv'
vsheets:
- DHCPentries:
- DC
- Tenant
- BD
- AppProfile
- DHCP
- EPG
- name: Associate multiple DHCP servers with a Tenant, Bridge Domain
debug:
msg: 'Apply to tenant={{ item.0.Tenant }} BD={{ item.0.BD }} DHCP Label={{ item.1.key }} server={{ item.1.value.addr }} dn={{ item.1.value.dn }}'
with_nested:
- '{{ DHCPentries }}' # item.0.blah
- '{{ dhcp.server | dict2items }}' # item.1.key item.1.value.blah
when:
- item.0.DC == data_center
- item.0.DHCP|bool