Adding parameter to synchronize module to suppress verbose output and print error only

This commit is contained in:
Mandar Kulkarni 2021-07-11 22:39:10 -07:00
parent 542643e786
commit d0d7f7d362

View file

@ -419,6 +419,7 @@ def main():
delay_updates=dict(type='bool', default=True), delay_updates=dict(type='bool', default=True),
mode=dict(type='str', default='push', choices=['pull', 'push']), mode=dict(type='str', default='push', choices=['pull', 'push']),
link_dest=dict(type='list', elements='str'), link_dest=dict(type='list', elements='str'),
print_err_only=dict(type='bool',default=False)
), ),
supports_check_mode=True, supports_check_mode=True,
) )
@ -459,6 +460,7 @@ def main():
verify_host = module.params['verify_host'] verify_host = module.params['verify_host']
link_dest = module.params['link_dest'] link_dest = module.params['link_dest']
delay_updates = module.params['delay_updates'] delay_updates = module.params['delay_updates']
print_err_only = module.params['print_err_only']
if '/' not in rsync: if '/' not in rsync:
rsync = module.get_bin_path(rsync, required=True) rsync = module.get_bin_path(rsync, required=True)
@ -608,6 +610,10 @@ def main():
else: else:
(rc, out, err) = module.run_command(cmdstr) (rc, out, err) = module.run_command(cmdstr)
# If print_errors_only is true, supress the verbose output by suppressing changes but allowing errors
if print_err_only:
return module.fail_json(msg=err)
if rc: if rc:
return module.fail_json(msg=err, rc=rc, cmd=cmdstr) return module.fail_json(msg=err, rc=rc, cmd=cmdstr)