mirror of
https://github.com/ansible-collections/community.routeros.git
synced 2025-06-24 10:48:49 +02:00
Make command always return changed=true. (#50)
This commit is contained in:
parent
5042905471
commit
f9d246cd7a
3 changed files with 12 additions and 7 deletions
2
changelogs/fragments/50-command-changed.yml
Normal file
2
changelogs/fragments/50-command-changed.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
breaking_changes:
|
||||||
|
- "command - the module now always indicates that a change happens. If this is not correct, please use ``changed_when`` to determine the correct changed status for a task (https://github.com/ansible-collections/community.routeros/pull/50)."
|
|
@ -15,6 +15,9 @@ description:
|
||||||
read from the device. This module includes an
|
read from the device. This module includes an
|
||||||
argument that will cause the module to wait for a specific condition
|
argument that will cause the module to wait for a specific condition
|
||||||
before returning or timing out if the condition is not met.
|
before returning or timing out if the condition is not met.
|
||||||
|
- The module always indicates a (changed) status. You can use
|
||||||
|
R(the changed_when task property,override_the_changed_result) to determine
|
||||||
|
whether a command task actually resulted in a change or not.
|
||||||
options:
|
options:
|
||||||
commands:
|
commands:
|
||||||
description:
|
description:
|
||||||
|
@ -168,7 +171,7 @@ def main():
|
||||||
module.fail_json(msg=msg, failed_conditions=failed_conditions)
|
module.fail_json(msg=msg, failed_conditions=failed_conditions)
|
||||||
|
|
||||||
result.update({
|
result.update({
|
||||||
'changed': False,
|
'changed': True,
|
||||||
'stdout': responses,
|
'stdout': responses,
|
||||||
'stdout_lines': list(to_lines(responses))
|
'stdout_lines': list(to_lines(responses))
|
||||||
})
|
})
|
||||||
|
|
|
@ -61,20 +61,20 @@ class TestRouterosCommandModule(TestRouterosModule):
|
||||||
|
|
||||||
def test_command_simple(self):
|
def test_command_simple(self):
|
||||||
set_module_args(dict(commands=['/system resource print']))
|
set_module_args(dict(commands=['/system resource print']))
|
||||||
result = self.execute_module()
|
result = self.execute_module(changed=True)
|
||||||
self.assertEqual(len(result['stdout']), 1)
|
self.assertEqual(len(result['stdout']), 1)
|
||||||
self.assertTrue('platform: "MikroTik"' in result['stdout'][0])
|
self.assertTrue('platform: "MikroTik"' in result['stdout'][0])
|
||||||
|
|
||||||
def test_command_multiple(self):
|
def test_command_multiple(self):
|
||||||
set_module_args(dict(commands=['/system resource print', '/system resource print']))
|
set_module_args(dict(commands=['/system resource print', '/system resource print']))
|
||||||
result = self.execute_module()
|
result = self.execute_module(changed=True)
|
||||||
self.assertEqual(len(result['stdout']), 2)
|
self.assertEqual(len(result['stdout']), 2)
|
||||||
self.assertTrue('platform: "MikroTik"' in result['stdout'][0])
|
self.assertTrue('platform: "MikroTik"' in result['stdout'][0])
|
||||||
|
|
||||||
def test_command_wait_for(self):
|
def test_command_wait_for(self):
|
||||||
wait_for = 'result[0] contains "MikroTik"'
|
wait_for = 'result[0] contains "MikroTik"'
|
||||||
set_module_args(dict(commands=['/system resource print'], wait_for=wait_for))
|
set_module_args(dict(commands=['/system resource print'], wait_for=wait_for))
|
||||||
self.execute_module()
|
self.execute_module(changed=True)
|
||||||
|
|
||||||
def test_command_wait_for_fails(self):
|
def test_command_wait_for_fails(self):
|
||||||
wait_for = 'result[0] contains "test string"'
|
wait_for = 'result[0] contains "test string"'
|
||||||
|
@ -92,13 +92,13 @@ class TestRouterosCommandModule(TestRouterosModule):
|
||||||
wait_for = ['result[0] contains "MikroTik"',
|
wait_for = ['result[0] contains "MikroTik"',
|
||||||
'result[0] contains "test string"']
|
'result[0] contains "test string"']
|
||||||
set_module_args(dict(commands=['/system resource print'], wait_for=wait_for, match='any'))
|
set_module_args(dict(commands=['/system resource print'], wait_for=wait_for, match='any'))
|
||||||
self.execute_module()
|
self.execute_module(changed=True)
|
||||||
|
|
||||||
def test_command_match_all(self):
|
def test_command_match_all(self):
|
||||||
wait_for = ['result[0] contains "MikroTik"',
|
wait_for = ['result[0] contains "MikroTik"',
|
||||||
'result[0] contains "RB1100"']
|
'result[0] contains "RB1100"']
|
||||||
set_module_args(dict(commands=['/system resource print'], wait_for=wait_for, match='all'))
|
set_module_args(dict(commands=['/system resource print'], wait_for=wait_for, match='all'))
|
||||||
self.execute_module()
|
self.execute_module(changed=True)
|
||||||
|
|
||||||
def test_command_match_all_failure(self):
|
def test_command_match_all_failure(self):
|
||||||
wait_for = ['result[0] contains "MikroTik"',
|
wait_for = ['result[0] contains "MikroTik"',
|
||||||
|
@ -110,4 +110,4 @@ class TestRouterosCommandModule(TestRouterosModule):
|
||||||
def test_command_wait_for_2(self):
|
def test_command_wait_for_2(self):
|
||||||
wait_for = 'result[0] contains "wireless"'
|
wait_for = 'result[0] contains "wireless"'
|
||||||
set_module_args(dict(commands=['/system package print'], wait_for=wait_for))
|
set_module_args(dict(commands=['/system package print'], wait_for=wait_for))
|
||||||
self.execute_module()
|
self.execute_module(changed=True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue