summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNilashish Chakraborty <nilashishchakraborty8@gmail.com>2020-07-28 20:57:08 +0530
committerGitHub <noreply@github.com>2020-07-28 15:27:08 +0000
commit1795b189f7a3ca83ff3c67e189cfd1c83cc4b433 (patch)
tree0e40b8b55f0fea4d4af3bf9a8cec28a875cd1d3b
parentfbb82a0875dacc8200d3f663c3286104d0a1afbf (diff)
downloadvyos-ansible-old-1795b189f7a3ca83ff3c67e189cfd1c83cc4b433.tar.gz
vyos-ansible-old-1795b189f7a3ca83ff3c67e189cfd1c83cc4b433.zip
Make config modules work properly when module alias is used in task (#67)
Make config modules work properly when module alias is used in task Reviewed-by: https://github.com/apps/ansible-zuul
-rw-r--r--changelogs/fragments/fix_src_backup_with_module_alias.yaml3
-rw-r--r--plugins/action/vyos.py4
-rw-r--r--tests/integration/targets/vyos_config/templates/config.j22
-rw-r--r--tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml42
4 files changed, 50 insertions, 1 deletions
diff --git a/changelogs/fragments/fix_src_backup_with_module_alias.yaml b/changelogs/fragments/fix_src_backup_with_module_alias.yaml
new file mode 100644
index 0000000..fb641c9
--- /dev/null
+++ b/changelogs/fragments/fix_src_backup_with_module_alias.yaml
@@ -0,0 +1,3 @@
+---
+bugfixes:
+ - Make `src`, `backup` and `backup_options` in vyos_config work when module alias is used (https://github.com/ansible-collections/vyos.vyos/pull/67).
diff --git a/plugins/action/vyos.py b/plugins/action/vyos.py
index cab2f3f..9519d36 100644
--- a/plugins/action/vyos.py
+++ b/plugins/action/vyos.py
@@ -42,7 +42,9 @@ class ActionModule(ActionNetworkModule):
del tmp # tmp no longer has any effect
module_name = self._task.action.split(".")[-1]
- self._config_module = True if module_name == "vyos_config" else False
+ self._config_module = (
+ True if module_name in ["vyos_config", "config"] else False
+ )
persistent_connection = self._play_context.connection.split(".")[-1]
warnings = []
diff --git a/tests/integration/targets/vyos_config/templates/config.j2 b/tests/integration/targets/vyos_config/templates/config.j2
new file mode 100644
index 0000000..fc4d42c
--- /dev/null
+++ b/tests/integration/targets/vyos_config/templates/config.j2
@@ -0,0 +1,2 @@
+set interfaces ethernet eth0 description TEST-INTF
+set system login user test_user
diff --git a/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml b/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml
index ac84154..3f3e489 100644
--- a/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml
+++ b/tests/integration/targets/vyos_config/tests/redirection/cli/shortname.yaml
@@ -54,4 +54,46 @@
that:
- '{{ result.filtered|length }} == 2'
+- name: Remove interface description and delete temp user
+ vyos.vyos.config: &cleanup
+ lines:
+ - "delete interfaces ethernet eth0 description TEST-INTF"
+ - "delete system login user test_user"
+
+- name: Use src with module alias
+ register: result
+ vyos.vyos.config:
+ src: config.j2
+
+- assert:
+ that:
+ - result.changed == true
+ - '"set interfaces ethernet eth0 description TEST-INTF" in result.commands'
+ - '"set system login user test_user" in result.commands'
+
+- name: "Restore hostname to {{ inventory_hostname }} and delete temp user"
+ vyos.vyos.config: *cleanup
+
+- name: use module alias to take configuration backup
+ register: result
+ vyos.vyos.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 cli/shortname.yaml on connection={{ ansible_connection }}"