Skip to content

Commit

Permalink
Add Helper playbook
Browse files Browse the repository at this point in the history
  • Loading branch information
itdependsnetworks authored and GGabriele committed Feb 21, 2017
1 parent 3b8cd26 commit 64c5b1b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
46 changes: 46 additions & 0 deletions helpers/create-parsed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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: "{{ root_dir | default('..') }}"

- 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"
4 changes: 4 additions & 0 deletions helpers/make-parsed.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
parsed_sample:

{{ value.get('response') | to_nice_yaml }}

0 comments on commit 64c5b1b

Please sign in to comment.