Skip to content

Commit

Permalink
Relax restrictions on replace option with block and src (#945)
Browse files Browse the repository at this point in the history
* Relax restrictions on replace option with block and src

* fix tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Ashwini Mhatre <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 26, 2023
1 parent bbfdcbd commit a2a0dc4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/fix_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- "ios_config - Relax restrictions on I(src) parameter so it can be used more like I(lines)."
6 changes: 3 additions & 3 deletions plugins/modules/ios_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ def main():
)
mutually_exclusive = [("lines", "src"), ("parents", "src")]
required_if = [
("match", "strict", ["lines"]),
("match", "exact", ["lines"]),
("replace", "block", ["lines"]),
("match", "strict", ["lines", "src"], True),
("match", "exact", ["lines", "src"], True),
("replace", "block", ["lines", "src"], True),
("diff_against", "intended", ["intended_config"]),
]
module = AnsibleModule(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ip access-list extended test
permit ip host 192.0.2.1 any log
permit ip host 192.0.2.2 any log
permit ip host 192.0.2.3 any log
28 changes: 28 additions & 0 deletions tests/integration/targets/ios_config/tests/cli/replace_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- ansible.builtin.debug: msg="START cli/replace_block.yaml on connection={{ ansible_connection }}"

- name: "setup"
cisco.nxos.nxos_config:
lines:
- "no ip access-list extended test"

- name: "Populate nxos acls configuration with replace block and lines options"
register: result1
cisco.ios.ios_config:
lines: "{{ lookup('template', 'basic/acl_config.j2') }}"
replace: block

- ansible.builtin.assert:
that:
- result1.changed == true

- name: "Populate acl configuration with replace block and src options"
register: result2
cisco.ios.ios_config:
src: basic/acl_config.j2
replace: block

- ansible.builtin.assert:
that:
- result2.changed == true
- result1.commands == result2.commands
9 changes: 9 additions & 0 deletions tests/unit/modules/network/ios/test_ios_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ def test_ios_config_replace_block(self):
commands = parents + lines
self.execute_module(changed=True, commands=commands)

def test_ios_config_replace_block_src(self):
src = load_fixture("ios_config_src.cfg")
set_module_args(dict(src=src, replace="block"))
self.conn.get_diff = MagicMock(
return_value=self.cliconf_obj.get_diff(src, self.running_config),
)
commands = ["hostname foo", "interface GigabitEthernet0/0", "no ip address"]
self.execute_module(changed=True, commands=commands)

def test_ios_config_match_none(self):
lines = ["hostname router"]
set_module_args(dict(lines=lines, match="none"))
Expand Down

0 comments on commit a2a0dc4

Please sign in to comment.