有条件运行角色是否有标准或最佳实践?有条件地运行角色的最佳实践
如果我有以下的基本剧本:
---
- hosts: prod
gather_facts: false
become: true
become_method: sudo
vars_files:
- variables/vars.yml
pre_tasks:
- name: check app existence
command: ls /data/myapp
# Store the resuts here
register: app_exists
ignore_errors: yes
roles:
- os_base_setup
- selinux_setup
- libsemanage_install
...
# Conditionally run this role
- - { role: app_clean_install, when: app_exists|failed }
- post_install_config
- cleanup
...
缺点,我可以看到这种方法:
这始终报告“前置任务”为已经做了“变化”。
它还会将每个单独的任务与“跳过”角色报告为跳过,而不是仅跳过整个角色。
在某处键入问号并不一定会成为问题。 – techraf
感谢您的反馈......这个问题没有明确说明,所以我做了一个编辑。 – comfytoday