o nnh@sjddlmZdZdZdZddlZddlZddlmZddl m Z ddl m Z d d Z ed kr3e dSdS) ) annotationsa} --- module: async_status short_description: Obtain status of asynchronous task description: - This module gets the status of an asynchronous task. - This module is also supported for Windows targets. version_added: "0.5" options: jid: description: - Job or task identifier type: str required: true mode: description: - If V(status), obtain the status. - If V(cleanup), clean up the async job cache (by default in C(~/.ansible_async/)) for the specified job O(jid), without waiting for it to finish. type: str choices: [ cleanup, status ] default: status extends_documentation_fragment: - action_common_attributes - action_common_attributes.flow attributes: action: support: full async: support: none check_mode: support: full version_added: '2.17' diff_mode: support: none bypass_host_loop: support: none platform: support: full platforms: posix, windows seealso: - ref: playbooks_async description: Detailed information on how to use asynchronous actions and polling. author: - Ansible Core Team - Michael DeHaan a --- - name: Asynchronous dnf task ansible.builtin.dnf: name: docker-io state: present async: 1000 poll: 0 register: dnf_sleeper - name: Wait for asynchronous job to end ansible.builtin.async_status: jid: '{{ dnf_sleeper.ansible_job_id }}' register: job_result until: job_result.finished retries: 100 delay: 10 - name: Clean up async file ansible.builtin.async_status: jid: '{{ dnf_sleeper.ansible_job_id }}' mode: cleanup a ansible_job_id: description: The asynchronous job id returned: success type: str sample: '360874038559.4169' finished: description: Whether the asynchronous job has finished (V(1)) or not (V(0)) returned: always type: int sample: 1 started: description: Whether the asynchronous job has started (V(1)) or not (V(0)) returned: always type: int sample: 1 stdout: description: Any output returned by async_wrapper returned: always type: str stderr: description: Any errors returned by async_wrapper returned: always type: str erased: description: Path to erased job file returned: when file is erased type: str N) AnsibleModule) iteritems to_nativec Csptttdddtddddgdtdddddd }|jd }|jd }|jd }tj||}tj|s?|jd |ddd|dkrOt||j ||dd}zt |}t | }Wdn1shwYWn!ty|s|j ||dddn |j||d|dddYnwd|vrd|d<||d<nd|vrd|d<ddt|D}|j di|dS)NstrT)typerequiredstatuscleanup)rdefaultchoicespath)jidmode _async_dir) argument_specsupports_check_moderrrzcould not find job)msgansible_job_idstartedfinished)rerasedr) results_filerrrzCould not parse job output: %s)rrrrrrrrcSsi|] \}}t||qSr).0kvrrG/usr/local/lib/python3.10/dist-packages/ansible/modules/async_status.py szmain..r)rdictparamsosrjoinexists fail_jsonunlink exit_jsonopenjsonloadsread Exceptionr)modulerr async_dirlog_pathdatafrrrmainvsL          r3__main__) __future__r DOCUMENTATIONEXAMPLESRETURNr*r#ansible.module_utils.basicransible.module_utils.sixr+ansible.module_utils.common.text.convertersrr3__name__rrrrs /   6