-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_snake.yml
127 lines (113 loc) · 3.4 KB
/
clean_snake.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
- hosts: dut
connection: local
gather_facts: no
vars:
state: present
snake_tag: snake
roles:
- ansible-nfvis
tags:
- facts
tasks:
- name: Get NFVIS facts
nfvis_facts:
host: "{{ ansible_host }}"
user: "{{ ansible_user }}"
password: "{{ ansible_password }}"
register: nfvis_facts
- set_fact:
deployments: "{{ nfvis_facts.deployments.deployment }}"
when: nfvis_facts.deployments
- set_fact:
snake_vnfs: "{{ nfvis_facts.deployments.deployment | selectattr('name', 'search', '^' + snake_tag + '-') | map(attribute='name') | list }}"
when: nfvis_facts.deployments
- debug:
msg: "Cleaning the following snake VNFs: {{ snake_vnfs|default([]) | join(',') }}"
- name: Add VNF to inventory
add_host:
name: "{{ item.name }}"
ansible_port: "{{ item.vm_group[0].interfaces.interface[0].port_forwarding.port[0].external_port_range[0].start }}"
ansible_host: "{{ ansible_host }}"
groups: snake_test
loop: "{{ deployments|default([]) }}"
when: item.name is search(snake_regexp)
vars:
snake_regexp: '^{{ snake_tag }}-'
- hosts: snake_test
connection: network_cli
gather_facts: no
tags:
- deregister
roles:
- ansible-nfvis
tasks:
- name: Deregister from smart account
ios_command:
commands:
- "license smart deregister"
- hosts: dut
connection: local
gather_facts: no
vars:
state: present
snake_tag: snake
roles:
- ansible-nfvis
tags:
- facts
tasks:
- name: Get NFVIS facts
nfvis_facts:
host: "{{ ansible_host }}"
user: "{{ ansible_user }}"
password: "{{ ansible_password }}"
register: nfvis_facts
- set_fact:
snake_vnfs: "{{ nfvis_facts.deployments.deployment | selectattr('name', 'search', '^' + snake_tag + '-') | map(attribute='name') | list }}"
when: nfvis_facts.deployments
- set_fact:
snake_bridges: "{{ nfvis_facts.bridges.bridge | selectattr('name', 'search', '^' + snake_tag + '-net[0-9]') | map(attribute='name') | list }}"
when: nfvis_facts.bridges
- set_fact:
snake_networks: "{{ nfvis_facts.networks.network | selectattr('name', 'search', '^' + snake_tag + '-net[0-9]') | map(attribute='name') | list }}"
when: nfvis_facts.networks
- name: Clean snake VNFs
nfvis_deployment:
host: "{{ ansible_host }}"
user: "{{ ansible_user }}"
password: "{{ ansible_password }}"
name: "{{ item }}"
state: absent
loop: "{{ snake_vnfs | default([]) }}"
register: deployment_results
until: "'OK' in deployment_results.response"
retries: 6
delay: 10
- name: Clean snake networks
nfvis_network:
host: "{{ ansible_host }}"
user: "{{ ansible_user }}"
password: "{{ ansible_password }}"
name: "{{ item }}"
state: absent
loop: "{{ snake_networks | default([]) }}"
register: network_results
until: "'OK' in network_results.response"
retries: 6
delay: 10
- name: Clean snake bridges
nfvis_bridge:
host: "{{ ansible_host }}"
user: "{{ ansible_user }}"
password: "{{ ansible_password }}"
name: "{{ item }}"
state: absent
loop: "{{ snake_bridges | default([]) }}"
register: bridge_results
until: "'OK' in bridge_results.response"
retries: 6
delay: 10
- name: Remove DUT from known_hosts
known_hosts:
name: "{{ ansible_host }}"
state: absent