Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax restrictions on replace option with block and src #945

Merged
Merged
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
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
Loading