1
我希望有條件地運行Ansible角色,即僅當某些二進制文件不存在時(對於我來說,這意味着某些特定應用程序安裝不存在)。Ansible中的條件角色包含失敗
類似於使用的圖案here。
在我的劇本使用下面的代碼:
- hosts: my_host
tasks:
- name: check app existence
command: /opt/my_app/somebinary
register: myapp_exists
ignore_errors: yes
roles:
- { role: myconditional_role, when: myapp_exists|failed }
- another_role_to_be_included_either_way
這裏是輸出:
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [my_host ]
TASK [ myconditional_role : create temporary installation directory] ***********************
fatal: [my_host]: FAILED! => {"failed": true, "msg": "ERROR! The conditional check 'myapp_exists|failed' failed. The error was: ERROR! |failed expects a dictionary"}
爲什麼條件檢查失敗?
上Ubuntu 16.04.01
使用ansible 2.0.0.2
順便說一句:「創建臨時安裝目錄」是有條件地包括角色的第一主任務的名稱。
因此,針對特定用例的任何建議的條件角色包含模式? – pkaramol
我會在角色的main.yml任務文件中移動測試,並在需要時包含install.yml。 –