在并发异步任务失败上失败Ansible播放
我有一个Ansible Play(在包含的几本剧本中分开),看起来有点像这样:
- name: Build packer images
<snip>
register: packer_run
async: 2700 # 45 minutes
poll: 0
- name: Do other stuff
<snip>
...
- name: Check Packer build finished
async_status:
jid: "{{ packer_run.ansible_job_id }}"
register: packer_result
until: packer_result.finished
retries: 30 # allow 15 mins
delay: 30
注意ASYNC任务集poll = 0
,以允许随后的任务同时运行。但是,即使异步任务立即失败,Ansible也仅在完成后续任务并检查异步任务状态后才失败。这真的很烦人,因为发现异步任务失败了30秒,可能需要30分钟。
有没有办法保留并发行为,但是在异步任务失败后立即失败?
我猜显而易见的答案是“不要与Ansible同时发生”,但是由于这在GitHub Action中运行(不允许并发步骤)使用此方法提供了合理的解决方法,除了这个“慢速失败”问题。
I've got an ansible play (split across several included playbooks) which looks a bit like this:
- name: Build packer images
<snip>
register: packer_run
async: 2700 # 45 minutes
poll: 0
- name: Do other stuff
<snip>
...
- name: Check Packer build finished
async_status:
jid: "{{ packer_run.ansible_job_id }}"
register: packer_result
until: packer_result.finished
retries: 30 # allow 15 mins
delay: 30
Note the async task sets poll=0
to allow subsequent tasks to run concurrently. However even if the async task fails immediately, ansible only fails once it's finished the subsequent tasks and checks on the async task status. Which is really annoying because it can take ~30 minutes to find out that the async task failed 30s in to the run.
Is there a way to preserve the concurrent behaviour but have ansible fail as soon as the async task fails?
I guess the obvious answer is "don't do the concurrency with ansible" but as this is running in a github actions workflow (which doesn't allow concurrent steps) using this approach provides a reasonable workaround apart from this "slow failure" problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使“构建包装器映像”任务立即失败,只有在达到“ Check Packer build thargy”时才检查任务的状态。
或“构建Packer Images”记录某些文件和其他任务中的状态。
每当需要检查状态时,我们都可以保持“检查包装器构建”。在剧本中的不同点上多次检查它。无论如何,如果没有人检查任务是否失败,则永远不会在Ansible控制台中获得该信息。
Even though 'Build packer images' task fails immediately, the status of the task is only checked when 'Check Packer build finished' is reached.
Or 'Build packer images' logs the status in some file and other tasks read that.
We can keep 'Check Packer build finished' whenever we need to check the status. Check it multiple time at different points in the playbook. In any case if no one is checking if the task is failed, will never get that info in ansible console.