gpt4 book ai didi

Ansible 始终运行角色

转载 作者:行者123 更新时间:2023-12-02 10:06:48 26 4
gpt4 key购买 nike

有什么办法可以一直运行一个角色吗?我在开始之前创建锁定文件 任何防止并行部署的部署。如果发生任何失败/成功,我 想要删除锁定文件。

- { role: lock-deployment, tags: always }
- { role: fetch-artifactory, tags: always }
- { role: unlock-deployment, tags: always }

无论失败/成功,我都想运行解锁部署角色。

最佳答案

problem is I don't want to do block, rescue for every task. I just want to delete lock file in case of failure in any of the task. I tried looking around if role itself can be put into block but didn't find any. ref

可以blockalways结构一起使用。角色可以包含在 include_role 中:

tasks:
- include_role:
name: lock-deployment
- block:
- include_role:
name: fetch-artifactory
always:
- include_role:
name: unlock-deployment

这会产生您想要的流程(fetch-artifactory 包含用于模拟失败的 fail 任务):

PLAY [localhost] ***************************************************************************************

TASK [include_role] ************************************************************************************

TASK [lock-deployment : file] **************************************************************************
changed: [localhost]

TASK [include_role] ************************************************************************************

TASK [fetch-artifactory : fail] ************************************************************************
Unaltered: {'msg': u'Failed as requested from task', 'failed': True, 'changed': False}
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed as requested from task"}

TASK [include_role] ************************************************************************************

TASK [unlock-deployment : file] **********************************************************************
changed: [localhost]

关于Ansible 始终运行角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47575257/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com