2

How can I specify an Ansible role and its argument in the dependency list of dependent role, both of which are stored in separate Git repositories?

Consider the following incorrect example where role tomcat depends on version 8 of role openjdk:

# 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 }

What is the correct way to specify dependency role openjdk?

Ansible Galaxy version:

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 version:

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
Derek Mahar
  • 27,608
  • 43
  • 124
  • 174
  • 1
    I would set it as a role variable in `var/main.yml`. Does it works for you? – Andrii Rusanov Nov 10 '16 at 10:45
  • Btw, accotding to this link: https://galaxy.ansible.com/intro#meta your file is correct – Andrii Rusanov Nov 10 '16 at 10:47
  • See http://docs.ansible.com/ansible/galaxy.html#dependencies which I included in my question. Neither `ansible-galaxy` nor `ansible-playbook` complain about the syntax, but `ansible-playbook` ultimately fails complaining that `openjdk_version` is undefined. I did also think of placing it in `vars/main.yml` as a workaround, though. – Derek Mahar Nov 10 '16 at 11:59
  • What ansible version do you use? It might be an issue with specific version. – Andrii Rusanov Nov 10 '16 at 12:50
  • @AndreyRusanov, I updated my question with Ansible version details. – Derek Mahar Nov 10 '16 at 18:24

1 Answers1

1

As I could not find a way to pass openjdk_version as an argument to role openjdk, I instead followed Andrey Rusanov's suggestion and added variable openjdk_version to vars/main.yml of role tomcat:

---
openjdk_version: 8

meta/main.yml now contains only the src dependency for openjdk:

# 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
Community
  • 1
  • 1
Derek Mahar
  • 27,608
  • 43
  • 124
  • 174