Debian Codegraph @

lib/ansible/plugins/action/fail.py

raw
1 # (c) 2012-2014, Michael DeHaan <[email protected]>
2 # (c) 2012, Dag Wieers <[email protected]>
3 #
4 # This file is part of Ansible
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18 from __future__ import annotations
19
20 from ansible.plugins.action import ActionBase
21
22
23 class ActionModule(ActionBase):
24 """ Fail with custom message """
25
26 TRANSFERS_FILES = False
27 _VALID_ARGS = frozenset(('msg',))
28 _requires_connection = False
29
30 def run(self, tmp=None, task_vars=None):
31 if task_vars is None:
32 task_vars = dict()
33
34 result = super(ActionModule, self).run(tmp, task_vars)
35 del tmp # tmp no longer has any effect
36
37 msg = 'Failed as requested from task'
38 if self._task.args and 'msg' in self._task.args:
39 msg = self._task.args.get('msg')
40
41 result['failed'] = True
42 result['msg'] = msg
43 return result