async support check mode (#82901)

Allow async tasks to run in check mode
Add check_mode support to async_status
Add tests, also for 'hidden' async mode in gather_facts/parallel
pull/82917/head
Brian Coca 2 months ago committed by GitHub
parent b639bd1fd4
commit fde206499d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
minor_changes:
- async tasks can now also support check mode at the same time.
- async_status now supports check mode.

@ -36,7 +36,8 @@ attributes:
async:
support: none
check_mode:
support: none
support: full
version_added: '2.17'
diff_mode:
support: none
bypass_host_loop:
@ -116,12 +117,15 @@ from ansible.module_utils.common.text.converters import to_native
def main():
module = AnsibleModule(argument_spec=dict(
jid=dict(type='str', required=True),
mode=dict(type='str', default='status', choices=['cleanup', 'status']),
# passed in from the async_status action plugin
_async_dir=dict(type='path', required=True),
))
module = AnsibleModule(
argument_spec=dict(
jid=dict(type="str", required=True),
mode=dict(type="str", default="status", choices=["cleanup", "status"]),
# passed in from the async_status action plugin
_async_dir=dict(type="path", required=True),
),
supports_check_mode=True,
)
mode = module.params['mode']
jid = module.params['jid']

@ -118,8 +118,6 @@ class ActionBase(ABC):
raise AnsibleActionFail('This action (%s) does not support async.' % self._task.action)
elif self._task.check_mode and not self._supports_check_mode:
raise AnsibleActionSkip('This action (%s) does not support check mode.' % self._task.action)
elif self._task.async_val and self._task.check_mode:
raise AnsibleActionFail('"check mode" and "async" cannot be used on same task.')
# Error if invalid argument is passed
if self._VALID_ARGS:

@ -310,3 +310,30 @@
- assert:
that:
- '"ASYNC OK on localhost" in check_task_disabled_output.stdout'
- name: test 'hidden' async, gather_facts does internal on parallel true. Ensure it won't freeze in check_mode due to async_status not supporting it.
gather_facts:
parallel: true
timeout: 60
check_mode: true
when: "ansible_facts['os_family'] != 'Darwin'"
vars:
ansible_facts_modules:
- setup
- package_facts
- service_facts
- name: test async in check mode
check_mode: true
block:
- setup:
async: 60
poll: 0
register: gf_async
- async_status:
jid: "{{ gf_async['ansible_job_id'] }}"
register: gf_done
until: gf_done is finished
retries: 100
delay: 10
timeout: 30

Loading…
Cancel
Save