replace - always return rc (#71963)

* Return rc=0 on success.

Error handling in playbooks generally expects `rc` to be set to 0 when a module has not failed.  Playbook authors should not have to check for the existence of `rc` first.

* Use single definition and added changelog

* Fix up tests with new return value

Co-authored-by: Jordan Borean <jborean93@gmail.com>
pull/77000/head
Jack Scheible 3 years ago committed by GitHub
parent b145732973
commit d35bef68f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- replace - Always return ``rc`` to ensure return values are consistent - https://github.com/ansible/ansible/pull/71963

@ -241,7 +241,7 @@ def main():
params = module.params
path = params['path']
encoding = params['encoding']
res_args = dict()
res_args = dict(rc=0)
params['after'] = to_text(params['after'], errors='surrogate_or_strict', nonstring='passthru')
params['before'] = to_text(params['before'], errors='surrogate_or_strict', nonstring='passthru')

@ -180,11 +180,13 @@ TASK [replace] *****************************************************************
changed: [testhost] =>
changed: true
msg: 1 replacements made
rc: 0
TASK [replace] *****************************************************************
ok: [testhost] =>
changed: false
msg: 1 replacements made
rc: 0
RUNNING HANDLER [Test handler 1] ***********************************************
changed: [testhost] =>

@ -187,11 +187,13 @@ TASK [replace] *****************************************************************
changed: [testhost] =>
changed: true
msg: 1 replacements made
rc: 0
TASK [replace] *****************************************************************
ok: [testhost] =>
changed: false
msg: 1 replacements made
rc: 0
RUNNING HANDLER [Test handler 1] ***********************************************
changed: [testhost] =>

Loading…
Cancel
Save