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

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

Merged
merged 2 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
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
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 }}"