forked from networktocode/ntc-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-parsed.yml
46 lines (35 loc) · 1.85 KB
/
create-parsed.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
---
# This Playbook will build the correct *.parsed file, based on the *.raw file. The presumption is you are running the playbook from the helpers folder, and it will find the correct test path.
# You can set extra vars for root_directory, os, command, and num ( which is a way to differentiate when you have multiple tests)
# Example command below, makes use of localhost,
# ansible-playbook -i localhost, create-parsed.yml --extra-vars="os=cisco_ios command='show mac-address-table'"
# Use number to differentiate raw and parsed files
# ansible-playbook -i localhost, create-parsed.yml --extra-vars="os=cisco_ios command='show mac-address-table' num=3"
# With library and python interperter set
# ansible-playbook -i localhost, create-parsed.yml --extra-vars="os=cisco_ios command='show ip bgp' ansible_python_interpreter=python" -M "/etc/modules/library"
- name: CREATE PARSED FILE FOR NTC TEMPLATES
hosts: localhost
gather_facts: no
connection: local
tasks:
- name: SET FACT FOR COMMAND
set_fact:
command_dash: "{{ command | regex_replace(' ', '_')}}"
- name: SET FACT FOR ROOT DIR
set_fact:
root_directory: "{{ playbook_dir | dirname }}"
- name: OFFLINE NTC SHOW COMMAND
ntc_show_command:
connection: "offline"
file: "{{ root_directory }}/tests/{{ os }}/{{ command_dash }}/{{ os }}_{{ command_dash}}{{ num | default('') }}.raw"
platform: '{{ os }}'
command: '{{ command }}'
template_dir: '{{ root_directory }}/templates/'
register: "value"
- name: DISPLAY IN JSON VALUES
debug:
var: "value"
- name: BUILD YAML FILE PARSED OUTPUT
template:
src: "./make-parsed.j2"
dest: "{{ root_directory }}/tests/{{ os }}/{{ command_dash }}/{{ os }}_{{ command_dash}}{{ num | default('') }}.parsed"