mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
async: use async_dir for the async results file directory (#45461)
* win async: use async_dir for the async results file directory * tried to unify POSIX and PowerShell async implementations of async_dir * fix sanity issue
This commit is contained in:
parent
60979a96a9
commit
5c73d4f4bd
11 changed files with 269 additions and 19 deletions
51
lib/ansible/plugins/action/async_status.py
Normal file
51
lib/ansible/plugins/action/async_status.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
# Copyright: (c) 2018, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.utils.vars import merge_hash
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
|
||||
_VALID_ARGS = frozenset(('jid', 'mode'))
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
results = super(ActionModule, self).run(tmp, task_vars)
|
||||
del tmp # tmp no longer has any effect
|
||||
|
||||
if "jid" not in self._task.args:
|
||||
raise AnsibleError("jid is required")
|
||||
jid = self._task.args["jid"]
|
||||
mode = self._task.args.get("mode", "status")
|
||||
|
||||
env_async_dir = [e for e in self._task.environment if
|
||||
"ANSIBLE_ASYNC_DIR" in e]
|
||||
if len(env_async_dir) > 0:
|
||||
# for backwards compatibility we need to get the dir from
|
||||
# ANSIBLE_ASYNC_DIR that is defined in the environment. This is
|
||||
# deprecated and will be removed in favour of shell options
|
||||
async_dir = env_async_dir[0]['ANSIBLE_ASYNC_DIR']
|
||||
|
||||
msg = "Setting the async dir from the environment keyword " \
|
||||
"ANSIBLE_ASYNC_DIR is deprecated. Set the async_dir " \
|
||||
"shell option instead"
|
||||
self._display.deprecated(msg, "2.12")
|
||||
else:
|
||||
# inject the async directory based on the shell option into the
|
||||
# module args
|
||||
try:
|
||||
async_dir = self._connection._shell.get_option('async_dir')
|
||||
except KeyError:
|
||||
# here for 3rd party shell plugin compatibility in case they do
|
||||
# not define the async_dir option
|
||||
async_dir = "~/.ansible_async"
|
||||
|
||||
module_args = dict(jid=jid, mode=mode, _async_dir=async_dir)
|
||||
status = self._execute_module(task_vars=task_vars,
|
||||
module_args=module_args)
|
||||
results = merge_hash(results, status)
|
||||
return results
|
Loading…
Add table
Add a link
Reference in a new issue