Debian Codegraph @

lib/ansible/plugins/action/async_status.py

raw
1 # Copyright: (c) 2018, Ansible Project
2 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3
4 from __future__ import annotations
5
6 from ansible.plugins.action import ActionBase
7 from ansible.utils.vars import merge_hash
8
9
10 class ActionModule(ActionBase):
11
12 def _get_async_dir(self):
13
14 # async directory based on the shell option
15 async_dir = self.get_shell_option('async_dir', default="~/.ansible_async")
16
17 return self._remote_expand_user(async_dir)
18
19 def run(self, tmp=None, task_vars=None):
20
21 results = super(ActionModule, self).run(tmp, task_vars)
22
23 validation_result, new_module_args = self.validate_argument_spec(
24 argument_spec={
25 'jid': {'type': 'str', 'required': True},
26 'mode': {'type': 'str', 'choices': ['status', 'cleanup'], 'default': 'status'},
27 },
28 )
29
30 # initialize response
31 results['started'] = results['finished'] = False
32 results['stdout'] = results['stderr'] = ''
33 results['stdout_lines'] = results['stderr_lines'] = []
34
35 jid = new_module_args["jid"]
36 mode = new_module_args["mode"]
37
38 results['ansible_job_id'] = jid
39 async_dir = self._get_async_dir()
40 log_path = self._connection._shell.join_path(async_dir, jid)
41
42 if mode == 'cleanup':
43 results['erased'] = log_path
44 else:
45 results['results_file'] = log_path
46 results['started'] = True
47
48 new_module_args['_async_dir'] = async_dir
49 results = merge_hash(results, self._execute_module(module_name='ansible.legacy.async_status', task_vars=task_vars, module_args=new_module_args))
50
51 # Backwards compat shim for when started/finished were ints,
52 # mostly to work with ansible.windows.async_status
53 for convert in ('started', 'finished'):
54 results[convert] = bool(results[convert])
55
56 return results