|
1 | 1 | --- |
| 2 | +- name: Generate gNMI YAML configuration |
| 3 | + set_fact: yaml_config={{ lookup('template',config_template) }} |
2 | 4 |
|
3 | | -- name: Check that required plugin exists, use 'netlab install grpc' to install it |
4 | | - vars: |
5 | | - ansible_connection: nokia.grpc.gnmi |
6 | | - register: plugin_checked |
7 | | - when: plugin_checked is not defined |
8 | | - nokia.grpc.gnmi_config: |
9 | | - prefix: test-plugin |
10 | | - |
11 | | -- local_action: |
12 | | - module: tempfile |
13 | | - state: file |
14 | | - suffix: temp |
15 | | - prefix: ansible.sros.{{ inventory_hostname }}. |
16 | | - register: tempfile_1 |
17 | | - |
18 | | -- name: Set default provisioning model to use OpenConfig (sros_use_openconfig={{sros_use_openconfig}}) |
19 | | - when: sros_use_openconfig|default(true) |
20 | | - set_fact: |
21 | | - sros_provisioning_model: "sros.openconfig" |
22 | | - |
23 | | -# - name: Example how to check if a BGP RR is being used |
24 | | -# vars: |
25 | | -# rr: "{{ groups['all']|map('extract',hostvars)|map(attribute='bgp.rr')|list }}" |
26 | | -# set_fact: |
27 | | -# uses_route_reflector: "{{ rr != [] }}" |
28 | | - |
29 | | -- name: Check if OpenConfig can be used as provisioning method/model (config_template={{config_template}}) |
30 | | - when: "'ospf' in config_template or 'sr' in module|default([]) or not sros_use_openconfig|default(True)" |
31 | | - set_fact: |
32 | | - sros_provisioning_model: "sros" # Default: without '.gnmi' |
33 | | - |
34 | | -- name: Select provisioning template netsim_action={{ netsim_action }} |
35 | | - set_fact: |
36 | | - template_to_use: "{{ config_template|replace('sros.j2',sros_provisioning_model+'.j2') }}" |
37 | | - |
38 | | -- name: Process template {{ template_to_use }} |
39 | | - local_action: |
40 | | - module: template |
41 | | - src: "{{ template_to_use }}" |
42 | | - dest: "{{ tempfile_1.path }}" |
43 | | - |
44 | | -- block: |
45 | | - - name: Show generated config from {{template_to_use}} based on {{tempfile_1.path}} |
46 | | - debug: msg="{{ cfg }}" verbosity=1 |
47 | | - |
48 | | - - name: Check that prepared config from {{template_to_use}} in {{tempfile_1.path}} is valid YAML |
49 | | - debug: msg="{{ cfg | from_yaml }}" verbosity=2 |
50 | | - |
51 | | - vars: |
52 | | - cfg: "{{ lookup('file', tempfile_1.path ) }}" |
53 | | - |
54 | | -- name: Wait up to 180s for gNMI(TCP {{sros_grpc_port}}) to be ready on {{ ansible_host }} |
55 | | - local_action: |
56 | | - module: wait_for |
57 | | - port: "{{ sros_grpc_port }}" |
58 | | - host: "{{ ansible_host }}" |
59 | | - connect_timeout: 60 |
60 | | - timeout: 180 |
61 | | - sleep: 10 # Wait 10s between attempts |
62 | | - |
63 | | -- block: |
64 | | - - block: |
65 | | - - name: Enable Open Config YAML modules (retry to give Containerlab a chance to finish configuration) |
66 | | - when: enable_open_config is not defined and 'ixr-ec' != clab.type |
67 | | - tags: [ initial ] |
68 | | - nokia.grpc.gnmi_config: |
69 | | - prefix: configure |
70 | | - update: |
71 | | - - path: system/management-interface/yang-modules/openconfig-modules |
72 | | - val: True # {{ sros_provisioning_model == "sros.openconfig" }} |
73 | | - register: enable_open_config |
74 | | - retries: 4 |
75 | | - delay: 15 |
76 | | - until: enable_open_config is success |
77 | | - |
78 | | - rescue: |
79 | | - - name: reset the gNMI connection, then try one more time |
80 | | - meta: reset_connection |
81 | | - |
82 | | - - debug: var=enable_open_config |
83 | | - # - debug: var=hostvars |
84 | | - |
85 | | - - name: Update {{ netsim_action }} node configuration (using gNMI SET based on YAML template {{template_to_use}}) |
86 | | - when: d or u or r |
87 | | - vars: |
88 | | - cfg: "{{ lookup('file', tempfile_1.path ) | from_yaml }}" |
89 | | - d: "{{ cfg.delete if 'delete' in cfg and cfg.delete is not string else [] }}" |
90 | | - u: "{{ cfg.updates if 'updates' in cfg and cfg.updates is not string else [] }}" |
91 | | - r: "{{ cfg.replace if 'replace' in cfg and cfg.replace is not string else [] }}" |
92 | | - nokia.grpc.gnmi_config: |
93 | | - # prefix: configure |
94 | | - delete: "{{ d }}" |
95 | | - replace: "{{ r }}" |
96 | | - update: "{{ u }}" |
97 | | - register: gnmi_set_result |
98 | | - retries: "{{ 2 if ansible_verbosity==0 else 0 }}" |
99 | | - until: gnmi_set_result is success |
100 | | - tags: [ print_action, always ] |
101 | | - |
102 | | - - debug: var=gnmi_set_result |
103 | | - |
| 5 | +- name: Update {{ netsim_action }} node configuration from gNMI template {{ config_template }} |
| 6 | + when: d or u or r |
104 | 7 | vars: |
| 8 | + cfg: "{{ yaml_config | from_yaml }}" |
| 9 | + d: "{{ cfg.delete if 'delete' in cfg and cfg.delete is not string else [] }}" |
| 10 | + u: "{{ cfg.updates if 'updates' in cfg and cfg.updates is not string else [] }}" |
| 11 | + r: "{{ cfg.replace if 'replace' in cfg and cfg.replace is not string else [] }}" |
105 | 12 | ansible_connection: nokia.grpc.gnmi |
106 | 13 | ansible_gnmi_encoding: JSON |
107 | 14 | ansible_port: "{{ sros_grpc_port }}" |
108 | | - |
109 | | -# Alternative: ansible.netcommon.cli_command |
110 | | -# Uses network_cli connection |
111 | | -# - community.network.sros_command: |
112 | | -# - nokia.sros.md: |
113 | | -# commands: "{{ lookup('file', tempfile_1.path ).splitlines() }}" |
114 | | - |
115 | | -# Let's use Netconf + OpenConfig |
116 | | -# - name: use lookup filter to provide xml configuration |
117 | | - #netconf_config: |
118 | | - # xml: "{{ lookup('file', tempfile_1.path) }}" |
119 | | - # host: "{{ ansible_host }}" |
120 | | - # username: "{{ ansible_user }}" |
121 | | - # password: "{{ ansible_ssh_pass }}" |
122 | | -# community.yang.configure: |
123 | | - |
124 | | -# - name: Fetch given yang model and its dependencies from remote host |
125 | | -# community.yang.fetch: |
126 | | -# # name: Nokia |
127 | | -# dir: "{{playbook_dir}}/{{inventory_hostname}}/yang_files" |
128 | | -# register: result |
129 | | -# |
130 | | -# - name: configure interface using structured data in JSON format |
131 | | -# community.yang.configure: |
132 | | -# config: "{{ lookup('file', tempfile_1.path) | to_json }}" |
133 | | -# file: "{{ playbook_dir }}/{{inventory_hostname}}/yang_files/Nokia-ifmgr-cfg.yang" |
134 | | -# search_path: "{{ playbook_dir }}/{{inventory_hostname}}/yang_files" |
135 | | -# register: result |
136 | | - |
137 | | -- local_action: |
138 | | - module: file |
139 | | - path: "{{ tempfile_1.path }}" |
140 | | - state: absent |
141 | | - when: tempfile_1.path is defined |
| 15 | + nokia.grpc.gnmi_config: |
| 16 | + # prefix: configure |
| 17 | + delete: "{{ d }}" |
| 18 | + replace: "{{ r }}" |
| 19 | + update: "{{ u }}" |
| 20 | + register: gnmi_set_result |
| 21 | + retries: "{{ 2 if ansible_verbosity==0 else 0 }}" |
| 22 | + until: gnmi_set_result is success |
| 23 | + tags: [ print_action, always ] |
| 24 | + |
| 25 | +- debug: var=gnmi_set_result |
| 26 | + when: ansible_verbosity |
0 commit comments