如何在另一个角色的依赖列表中指定一个 Ansible 角色及其参数?

How can I specify an Ansible role and its argument in the dependency list of another role?

如何指定一个 Ansible role and its argument in the dependency list 依赖角色,这两个角色都存储在单独的 Git 存储库中?

考虑以下不正确的示例,其中角色 tomcat 取决于角色 openjdk 的版本 8:

# Role tomcat at git+http://source/ansible/roles/tomcat.
# File tomcat/meta/main.yml.
---
dependencies:
  # When it retrieves role tomcat, ansible-galaxy retrieves role openjdk. 
  - src: git+http://source/ansible/roles/openjdk
    version: master

  # ansible-playbook invokes role openjdk, but fails to set openjdk_version.
  - { role: openjdk, openjdk_version: 8 }

指定依赖角色的正确方法是什么openjdk

Ansible Galaxy 版本:

derek@derek-lubuntu:~/Projects/deployer$ ansible-galaxy --version
ansible-galaxy 2.3.0 (devel 947e0f264e) last updated 2016/11/10 11:45:16 (GMT -400)
  lib/ansible/modules/core: (detached HEAD 2584fca0ae) last updated 2016/11/04 12:08:44 (GMT -400)
  lib/ansible/modules/extras: (detached HEAD a1dcbf9ce5) last updated 2016/11/04 12:08:44 (GMT -400)
  config file = /home/derek/Projects/deployer/ansible.cfg
  configured module search path = Default w/o overrides

Ansible Playbook 版本:

ansible-playbook 2.3.0 (devel 947e0f264e) last updated 2016/11/10 11:45:16 (GMT -400)
  lib/ansible/modules/core: (detached HEAD 2584fca0ae) last updated 2016/11/04 12:08:44 (GMT -400)
  lib/ansible/modules/extras: (detached HEAD a1dcbf9ce5) last updated 2016/11/04 12:08:44 (GMT -400)
  config file = /home/derek/Projects/deployer/ansible.cfg
  configured module search path = Default w/o overrides

因为我找不到将 openjdk_version 作为参数传递给角色 openjdk 的方法,所以我改为遵循 Andrey Rusanov's 并将变量 openjdk_version 添加到 [=15] =] 角色 tomcat:

---
openjdk_version: 8

meta/main.yml 现在只包含 srcopenjdk 的依赖:

# From role tomcat at git+http://source/ansible/roles/tomcat.
# File tomcat/meta/main.yml.
---
dependencies:
  - src: git+http://source/ansible/roles/openjdk
    version: master