diff options
author | omnom62 <75066712+omnom62@users.noreply.github.com> | 2025-05-08 05:52:44 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-08 05:52:44 +1000 |
commit | 098f31c6fe7a6310594656efc0af5a2739ede82b (patch) | |
tree | a459e02e00c8848638e66a6ff121853a3f6a217c | |
parent | 7a4f22fc4a63bad749b4128495d7dae8917d0b0e (diff) | |
download | vyos.vyos-main.tar.gz vyos.vyos-main.zip |
* T7259 get_config() fix
* fix get_config calls
* vyos_config match=none integration test case
* get_config() update
-rw-r--r-- | changelogs/fragments/T7259-get_config.yaml | 3 | ||||
-rw-r--r-- | plugins/module_utils/network/vyos/vyos.py | 5 | ||||
-rw-r--r-- | plugins/modules/vyos_config.py | 3 | ||||
-rw-r--r-- | tests/integration/targets/vyos_config/tests/cli/save.yaml | 4 | ||||
-rw-r--r-- | tests/integration/targets/vyos_config/tests/cli/simple.yaml | 11 |
5 files changed, 21 insertions, 5 deletions
diff --git a/changelogs/fragments/T7259-get_config.yaml b/changelogs/fragments/T7259-get_config.yaml new file mode 100644 index 00000000..84bb1ab4 --- /dev/null +++ b/changelogs/fragments/T7259-get_config.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - vyos_config - block get_config call if match is set to "none" diff --git a/plugins/module_utils/network/vyos/vyos.py b/plugins/module_utils/network/vyos/vyos.py index 1430b1b1..f37294e6 100644 --- a/plugins/module_utils/network/vyos/vyos.py +++ b/plugins/module_utils/network/vyos/vyos.py @@ -34,6 +34,7 @@ import json from ansible.module_utils._text import to_text from ansible.module_utils.connection import Connection, ConnectionError + _DEVICE_CONFIGS = {} @@ -68,8 +69,8 @@ def get_config(module, flags=None, format=None): flags = [] if flags is None else flags global _DEVICE_CONFIGS - if _DEVICE_CONFIGS != {}: - return _DEVICE_CONFIGS + if _DEVICE_CONFIGS != {} or module.params["match"] == "none": + return to_text(_DEVICE_CONFIGS) else: connection = get_connection(module) try: diff --git a/plugins/modules/vyos_config.py b/plugins/modules/vyos_config.py index 60be02c8..c6bc9959 100644 --- a/plugins/modules/vyos_config.py +++ b/plugins/modules/vyos_config.py @@ -286,6 +286,7 @@ def sanitize_config(config, result): def run(module, result): # get the current active config from the node or passed in via # the config param + config = module.params["config"] or get_config(module) # create the candidate config object from the arguments @@ -360,7 +361,7 @@ def main(): diff = run_commands(module, commands=["configure", "compare saved"])[1] if diff not in { "[edit]", - "No changes between working and saved configurations.\n\n[edit]" + "No changes between working and saved configurations.\n\n[edit]", }: if not module.check_mode: run_commands(module, commands=["save"]) diff --git a/tests/integration/targets/vyos_config/tests/cli/save.yaml b/tests/integration/targets/vyos_config/tests/cli/save.yaml index e8a9035b..b39ef957 100644 --- a/tests/integration/targets/vyos_config/tests/cli/save.yaml +++ b/tests/integration/targets/vyos_config/tests/cli/save.yaml @@ -6,7 +6,7 @@ lines: set system host-name {{ inventory_hostname_short }} match: none -- name: configure hostaname and save +- name: configure hostname and save register: result vyos.vyos.vyos_config: lines: set system host-name foo @@ -17,7 +17,7 @@ - result.changed == true - "'set system host-name foo' in result.commands" -- name: configure hostaname and don't save +- name: configure hostname and don't save register: result vyos.vyos.vyos_config: lines: set system host-name bar diff --git a/tests/integration/targets/vyos_config/tests/cli/simple.yaml b/tests/integration/targets/vyos_config/tests/cli/simple.yaml index 3db59270..1559fa2b 100644 --- a/tests/integration/targets/vyos_config/tests/cli/simple.yaml +++ b/tests/integration/targets/vyos_config/tests/cli/simple.yaml @@ -25,6 +25,17 @@ that: - result.changed == false +- name: configure simple config command while match = 'none' + register: result + vyos.vyos.vyos_config: + lines: set system host-name foo + match: none + +- assert: + that: + - result.changed == true + - "'set system host-name foo' in result.commands" + - name: Delete services vyos.vyos.vyos_config: &id001 lines: |