Skip to content
Draft
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
6 changes: 6 additions & 0 deletions changelogs/fragments/t6721-vyos_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bugfixes:
- vyos_config - Setting match="none" by default; updates to the documentation and tests
- The `match` parameter is now set to `none` by default in the `vyos_config` module.
- This change ensures that the module does not attempt to match existing configuration lines unless explicitly specified.
- Documentation and tests have been updated accordingly to reflect this change.
2 changes: 2 additions & 0 deletions docs/vyos.vyos.vyos_config_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ Examples
- set system host-name {{ inventory_hostname }}
- set service lldp
- delete service dhcp-server
match: line

- name: backup and load from file
vyos.vyos.vyos_config:
Expand All @@ -241,6 +242,7 @@ Examples
lines:
# - set int eth eth2 description 'OUTSIDE'
- set interface ethernet eth2 description 'OUTSIDE'
match: line

- name: configurable backup path
vyos.vyos.vyos_config:
Expand Down
9 changes: 8 additions & 1 deletion plugins/cliconf/vyos.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,18 @@ def get_diff(
visited = set()

for line in candidate_commands:

item = str(line).replace("'", "")

if not item.startswith("set") and not item.startswith("delete"):
raise ValueError("line must start with either `set` or `delete`")

elif item.startswith("set") and item not in running_commands:

updates.append(line)

elif item.startswith("delete"):
if item.startswith("delete"):

if not running_commands:
updates.append(line)
else:
Expand All @@ -277,6 +280,10 @@ def get_diff(
if entry.startswith(item) and line not in visited:
updates.append(line)
visited.add(line)
if entry.startswith(item) and entry in [
str(c).replace("'", "") for c in candidate_commands
]:
updates.append(entry)

diff["config_diff"] = list(updates)
return diff
Expand Down
2 changes: 2 additions & 0 deletions plugins/modules/vyos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
- set system host-name {{ inventory_hostname }}
- set service lldp
- delete service dhcp-server
match: line

- name: backup and load from file
vyos.vyos.vyos_config:
Expand All @@ -147,6 +148,7 @@
lines:
# - set int eth eth2 description 'OUTSIDE'
- set interface ethernet eth2 description 'OUTSIDE'
match: line

- name: configurable backup path
vyos.vyos.vyos_config:
Expand Down
49 changes: 49 additions & 0 deletions tests/integration/targets/vyos_config/tests/cli/resubmit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
- debug: msg="START cli/resubmit.yaml on connection={{ ansible_connection }}"

- name: setup
vyos.vyos.vyos_config:
lines: delete firewall group network-group

- name: setup
register: result
vyos.vyos.vyos_config:
lines:
- set firewall group network-group PUBLIC_DNS network '1.1.1.1/32'
- set firewall group network-group PUBLIC_DNS network '8.8.8.8/32'
- set firewall group network-group PUBLIC_DNS network '9.9.9.9/32'
match: none

- assert:
that:
- result.changed == true
- item in result.commands
loop:
- "set firewall group network-group PUBLIC_DNS network '9.9.9.9/32'"
- "set firewall group network-group PUBLIC_DNS network '1.1.1.1/32'"
- "set firewall group network-group PUBLIC_DNS network '8.8.8.8/32'"

- name: Ensure single transaction for resubmitted configuration (delete then provision)
register: result
vyos.vyos.vyos_config:
lines:
- delete firewall group network-group PUBLIC_DNS
- set firewall group network-group PUBLIC_DNS network '1.1.1.1/32'
- set firewall group network-group PUBLIC_DNS network '8.8.8.8/32'
- set firewall group network-group PUBLIC_DNS network '9.9.9.9/32'

- assert:
that:
- result.changed == true
- item in result.commands
loop:
- "delete firewall group network-group PUBLIC_DNS"
- "set firewall group network-group PUBLIC_DNS network 9.9.9.9/32"
- "set firewall group network-group PUBLIC_DNS network 1.1.1.1/32"
- "set firewall group network-group PUBLIC_DNS network 8.8.8.8/32"

- name: teardown
vyos.vyos.vyos_config:
lines: delete firewall group network-group PUBLIC_DNS

- debug: msg="END cli/resubmit.yaml on connection={{ ansible_connection }}"
12 changes: 12 additions & 0 deletions tests/unit/modules/network/vyos/test_vyos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,15 @@ def test_vyos_config_match_none(self):
return_value=self.cliconf_obj.get_diff(candidate, None, diff_match="none"),
)
self.execute_module(changed=True, commands=lines, sort=False)

def test_vyos_config_resubmit(self):
lines = [
"delete system name-server 8.8.4.4",
"set system name-server 8.8.4.4",
]
set_module_args(dict(lines=lines))
candidate = "\n".join(lines)
self.conn.get_diff = MagicMock(
return_value=self.cliconf_obj.get_diff(candidate, self.running_config),
)
self.execute_module(changed=True, commands=lines, sort=False)