【发布时间】:2022-07-25 18:57:00
【问题描述】:
我在 Ansible 中生成了几个异步任务,并尝试等待它们全部完成,然后再继续执行下一组任务(总共 9 个)。以下是其中的几个示例:
- name: EC2 spin up
async: 6000
poll: 0
shell: # spin up an instance with a playbook
register: ec2_item
when: deployment_type == 'x' or deployment_type == 'y'
- name: EC2 spin up another
async: 6000
poll: 0
shell: # # spin up another instance with a playbook
register: ec2_item_again
when: deployment_type == 'x' or deployment_type == 'y'
在这之后,我正在运行这个块来等待他们:
- name: Wait on EC2 Async Tasks
async_status:
jid: "{{ item.ansible_job_id }}"
with_items:
- "{{ ec2_item }}"
- "{{ ec2_item_again }}"
register: job_result
until: job_result.finished
retries: 60
delay: 15
最终,事情完成了,但没有他跟随就出错了:
fatal: [127.0.0.1]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'ansible_job_id'\n\nThe error appears to be in '/opt/app-root/src/playbooks/sb_build_flow.yml': line 201, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n delay: 6\n - async_status:\n ^ here\n"
}
它试图查看一个不再存在的任务,但我不确定如何实际完成这项工作。同样,我只是想让 Ansible 也等待异步任务完成后再继续。
【问题讨论】:
标签: asynchronous async-await ansible