Skip to content

Commit

Permalink
Make config modules work properly when module alias is used in task (#63
Browse files Browse the repository at this point in the history
)

Make config modules work properly when module alias is used in task 

Reviewed-by: https://github.com/apps/ansible-zuul
  • Loading branch information
NilashishC authored Jul 15, 2020
1 parent 8c0e7be commit 9099fbc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelogs/fragments/handle_src_backup_with_module_alias.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Make `src`, `backup` and `backup_options` in iosxr_config work when module alias is used (https://github.com/ansible-collections/cisco.iosxr/pull/63).
4 changes: 3 additions & 1 deletion plugins/action/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def run(self, tmp=None, task_vars=None):
del tmp # tmp no longer has any effect

module_name = self._task.action.split(".")[-1]
self._config_module = True if module_name == "iosxr_config" else False
self._config_module = (
True if module_name in ["iosxr_config", "config"] else False
)
force_cli = module_name in (
"iosxr_netconf",
"iosxr_config",
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/targets/iosxr_config/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
- include: cli.yaml
- include: cli_config.yaml

- include: redirection.yaml
when: ansible_version.full is version('2.10.0', '>=')
16 changes: 16 additions & 0 deletions tests/integration/targets/iosxr_config/tasks/redirection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: collect all redirection cli test cases
find:
paths: '{{ role_path }}/tests/redirection'
patterns: '{{ testcase }}.yaml'
register: shortname_test_cases
delegate_to: localhost

- name: set test_items for redirection
set_fact: test_items="{{ shortname_test_cases.files | map(attribute='path') | list }}"

- name: run test case (connection=ansible.netcommon.network_cli)
include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.network_cli'
with_items: '{{ test_items }}'
loop_control:
loop_var: test_case_to_run
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
- debug: msg="START redirection/shortname.yaml on connection={{ ansible_connection }}"

- name: Use src with module alias
register: result
cisco.iosxr.config:
src: basic/config.j2

- assert:
that:
# make sure that the template content was read and not the path
- result.changed == true
- result.updates is defined

- name: use module alias to take configuration backup
register: result
cisco.iosxr.config:
backup: true
backup_options:
filename: backup_with_alias.cfg
dir_path: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}'

- assert:
that:
- result.changed == true

- name: check if the backup file-4 exist
find:
paths: '{{ role_path }}/backup_test_dir/{{ inventory_hostname_short }}/backup_with_alias.cfg'
register: backup_file
connection: local

- assert:
that:
- backup_file.files is defined

- debug: msg="END redirection/shortname.yaml on connection={{ ansible_connection }}"

0 comments on commit 9099fbc

Please sign in to comment.