diff --git a/lib/ansible/runner/action_plugins/assert.py b/lib/ansible/runner/action_plugins/assert.py index b163d68a7b..a0e02dedb0 100644 --- a/lib/ansible/runner/action_plugins/assert.py +++ b/lib/ansible/runner/action_plugins/assert.py @@ -38,8 +38,7 @@ class ActionModule(object): args.update(complex_args) args.update(utils.parse_kv(module_args)) - msg = 'assertion failed' - + msg = None if 'msg' in args: msg = args['msg'] @@ -50,8 +49,16 @@ class ActionModule(object): args['that'] = [ args['that'] ] for that in args['that']: - result = utils.check_conditional(that, self.runner.basedir, inject, fail_on_undefined=True) - if not result: - return ReturnData(conn=conn, result=dict(failed=True, msg=msg, assertion=that, evaluated_to=result)) + test_result = utils.check_conditional(that, self.runner.basedir, inject, fail_on_undefined=True) + if not test_result: + result = dict( + failed = True, + evaluated_to = test_result, + assertion = that, + ) + if msg: + result['msg'] = msg + return ReturnData(conn=conn, result=result) return ReturnData(conn=conn, result=dict(msg='all assertions passed')) +