-
Notifications
You must be signed in to change notification settings - Fork 746
/
Copy pathtestbed_set_l2_mode.yml
63 lines (49 loc) · 1.95 KB
/
testbed_set_l2_mode.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
- hosts: sonic
gather_facts: no
tasks:
- name: Generate initial l2 mode config
shell: sonic-cfggen -H -k {{ hwsku }} -p --preset l2 > /tmp/init_l2_config.json
- name: Read the initial l2 config json content
shell: cat /tmp/init_l2_config.json
register: output
- name: Parse the initial l2 config json content to dict
set_fact:
l2_config: "{{ output.stdout | from_json }}"
- set_fact:
mgmt_addr: "{{ ansible_ssh_host + '/' + mgmt_subnet_mask_length | string }}"
- name: Prepare extra l2 configs
set_fact:
metadata: "{{ {'DEVICE_METADATA': {'localhost': {'type': 'ToRRouter', 'hostname': inventory_hostname}}} }}"
mgmt_interface: "{{ {'MGMT_INTERFACE': {'eth0|' + mgmt_addr: {'gwaddr': mgmt_addr | first_ip_of_subnet}}} }}"
mgmt_port: "{{ {'MGMT_PORT': {'eth0': {'admin_status': 'up', 'alias': 'eth0'}}} }}"
- name: Update l2 config with more configurations
set_fact:
l2_config: "{{ l2_config | combine(metadata, mgmt_interface, mgmt_port, recursive=True) }}"
- name: Backup the normal config_db.json file
shell: if [ ! -f /etc/sonic/config_db.json.normal ]; then cp /etc/sonic/config_db.json /etc/sonic/config_db.json.normal; fi
become: yes
- name: Dump the l2_config to /etc/sonic/config_db.json
copy:
content: "{{ l2_config | to_nice_json(indent=4) }}"
dest: /etc/sonic/config_db.json
become: yes
- name: Execute cli "config reload -y" to apply new config_db.json
shell: config reload -y
become: yes
- name: Wait for switch to become reachable again
local_action: wait_for
args:
host: "{{ ansible_host }}"
port: 22
state: started
search_regex: "OpenSSH_[\\w\\.]+ Debian"
delay: 10
timeout: 600
changed_when: false
- name: Wait some time for switch to stabilize
pause:
seconds: 60
- name: Check the new vlan config
shell: show vlan config
- name: Check interface status
shell: show int status