Skip to content

Commit

Permalink
Handle src & backup properly when module alias is used (#83)
Browse files Browse the repository at this point in the history
Handle src & backup properly when module alias is used

Reviewed-by: https://github.com/apps/ansible-zuul
  • Loading branch information
NilashishC authored Jul 28, 2020
1 parent 30baa30 commit fc55b82
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelogs/fragments/fix_config_module_src_backup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Make `src`, `backup` and `backup_options` in junos_config work when module alias is used (https://github.com/ansible-collections/junipernetworks.junos/pull/83).
4 changes: 3 additions & 1 deletion plugins/action/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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 == "junos_config" else False
self._config_module = (
True if module_name in ["junos_config", "config"] else False
)
persistent_connection = self._play_context.connection.split(".")[-1]
warnings = []

Expand Down
3 changes: 3 additions & 0 deletions tests/integration/targets/junos_config/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
- include: cli_config.yaml
tags:
- network_cli

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

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

- name: run test case (connection=ansible.netcommon.netconf)
include: '{{ test_case_to_run }} ansible_connection=ansible.netcommon.netconf'
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,51 @@
---
- debug: msg="START redirection/netconf/shortname.yaml on connection={{ ansible_connection }}"

- name: setup
junipernetworks.junos.config:
lines:
- delete interfaces lo0
provider: '{{ netconf }}'

- name: Use src with module alias
register: result
junipernetworks.junos.config:
src: basic/config.j2
provider: '{{ netconf }}'

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

- name: teardown
register: result
junipernetworks.junos.config:
lines:
- delete interfaces lo0
provider: '{{ netconf }}'

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

- 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/netconf/shortname.yaml on connection={{ ansible_connection }}"

0 comments on commit fc55b82

Please sign in to comment.