forked from networktocode/ntc-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-template.yml
42 lines (35 loc) · 1.31 KB
/
test-template.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
---
- name: Verify TextFSM template
hosts: localhost
gather_facts: False
vars_prompt:
- name: template_name
prompt: "Enter the name of the template to verify:"
default: "cisco_nxos_show_ip_route"
private: no
vars:
top_dir: "{{ lookup('env', 'PWD') }}"
TEST_DIR: "{{ top_dir }}/tests"
platform: "{{ template_name.split('_')[0:2] | join('_') }}"
command_variable: "{{ template_name.split(platform + '_') | last }}"
command: "{{ command_variable.split('_') | join(' ') }}"
tasks:
- name: "{{template_name}}: run TextFSM on test input"
ntc_show_command:
connection: offline
file: "{{ item }}"
platform: "{{ platform }}"
command: "{{ command }}"
template_dir: "{{ top_dir }}/templates"
with_fileglob:
- "{{ TEST_DIR }}/{{ platform }}/{{ command_variable }}/{{ template_name }}*.raw"
register: ntc_result
- name: "{{template_name}}: read parsed sample files"
include_vars: "{{ item.item | regex_replace('\\.raw$', '.parsed') }}"
with_items: "{{ ntc_result.results }}"
register: ntc_result
- name: "{{template_name}}: verify that parsed result is the same as expected"
with_items: "{{ ntc_result.results }}"
compare_dict:
result: "{{ item.item.response }}"
sample: "{{ item.ansible_facts.parsed_sample }}"