Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed test-template.yml to run in Ansible 2.3 #76

Merged
merged 1 commit into from
Mar 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions test-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,33 @@
default: "cisco_nxos_show_ip_route"
private: no

- name: platform
prompt: "Enter the platform"
default: "cisco_nxos"
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: extract command from template name
set_fact: command_variable="{{ template_name | split(platform + '_') | last }}"

- name: extract command string from command_variable
set_fact: command="{{ command_variable | split('_') | join(' ') }}"

- name: run TextFSM locally on test input
- 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"
- "{{ TEST_DIR }}/{{ platform }}/{{ command_variable }}/{{ template_name }}*.raw"
register: ntc_result

- name: read parsed sample files
- name: "{{template_name}}: read parsed sample files"
include_vars: "{{ item.item | regex_replace('\\.raw$', '.parsed') }}"
with_items: "{{ ntc_result.results }}"
register: ntc_result

- name: verify that parsed result is the same as expected
- 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 }}"
with_items: "{{ ntc_result.results }}"