diff --git a/lib/ansible/module_utils/network/vyos/config/interfaces/interfaces.py b/lib/ansible/module_utils/network/vyos/config/interfaces/interfaces.py index 791a3194a78..0d646ead307 100644 --- a/lib/ansible/module_utils/network/vyos/config/interfaces/interfaces.py +++ b/lib/ansible/module_utils/network/vyos/config/interfaces/interfaces.py @@ -108,6 +108,10 @@ class Interfaces(ConfigBase): """ commands = [] state = self._module.params['state'] + + if state in ('merged', 'replaced', 'overridden') and not want: + self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state)) + if state == 'overridden': commands.extend(self._state_overridden(want=want, have=have)) diff --git a/lib/ansible/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py b/lib/ansible/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py index 43ea03397af..4407b98727b 100644 --- a/lib/ansible/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py +++ b/lib/ansible/module_utils/network/vyos/config/l3_interfaces/l3_interfaces.py @@ -110,6 +110,10 @@ class L3_interfaces(ConfigBase): """ commands = [] state = self._module.params['state'] + + if state in ('merged', 'replaced', 'overridden') and not want: + self._module.fail_json(msg='value of config parameter must not be empty for state {0}'.format(state)) + if state == 'overridden': commands.extend(self._state_overridden(want=want, have=have)) diff --git a/test/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml b/test/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000000..319ab79faba --- /dev/null +++ b/test/integration/targets/vyos_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,36 @@ +--- +- debug: + msg: "START vyos_interfaces empty_config integration tests on connection={{ ansible_connection }}" + +- name: Merged with empty config should give appropriate error message + vyos_interfaces: + config: + state: merged + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty config should give appropriate error message + vyos_interfaces: + config: + state: replaced + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Overridden with empty config should give appropriate error message + vyos_interfaces: + config: + state: overridden + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state overridden' diff --git a/test/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml b/test/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml new file mode 100644 index 00000000000..026d95a3942 --- /dev/null +++ b/test/integration/targets/vyos_l3_interfaces/tests/cli/empty_config.yaml @@ -0,0 +1,36 @@ +--- +- debug: + msg: "START vyos_l3_interfaces empty_config integration tests on connection={{ ansible_connection }}" + +- name: Merged with empty config should give appropriate error message + vyos_l3_interfaces: + config: + state: merged + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state merged' + +- name: Replaced with empty config should give appropriate error message + vyos_l3_interfaces: + config: + state: replaced + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state replaced' + +- name: Overridden with empty config should give appropriate error message + vyos_l3_interfaces: + config: + state: overridden + register: result + ignore_errors: True + +- assert: + that: + - result.msg == 'value of config parameter must not be empty for state overridden'