Reputation: 13410
I am experimenting with Ansible (1.9.4) roles and I am trying to get the hang of role dependencies.
I have created the following roles:
The second role defines the first as a dependency in /ansible-tomcat7/meta/main.yml
:
dependencies:
- { role: java8 }
I also included a requirements.yml file with the following:
- name: java8
src: 'https://github.com/gregwhitaker/ansible-java8'
I have added the following configuration to my /etc/ansible/ansible.cfg
to configure my roles_path to a place in my home directory:
roles_path = ~/ansible/roles
I then installed the ansible-java8
role as java8
using the following command:
ansible-galaxy install -r requirements.yml
Once the command was ran I can see the java8 role in the ~/ansible/roles directory.
However, when I run a playbook that calls the tomcat7 role only that role is executed. The java8 role is not executed before the tomcat7 role.
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [default]
TASK: [Install Tomcat7 (Ubuntu)] **********************************************
changed: [default] => (item=tomcat7,libtcnative-1,libapr1)
TASK: [Install Tomcat7 (Debian)] **********************************************
skipping: [default]
TASK: [Install Tomcat7 (Amazon Linux)] ****************************************
skipping: [default]
PLAY RECAP ********************************************************************
default
Upvotes: 1
Views: 1706
Reputation: 13410
This turned out to be a problem with how I was testing the role.
I was telling Vagrant to provision my test box using the following site.yml file:
- hosts: all
sudo: yes
tasks:
- include: tasks/main.yml
This was obviously causing Ansible to only run the Tomcat tasks and not take into account that this was actually a role and not just a playbook with some tasks in it.
The site.yml playbook I am using for testing is at the root of the repository so once I changed it to reference the repository as a role everything started working.
- hosts: all
sudo: yes
roles:
- { role: '../ansible-tomcat7' }
Upvotes: 1