1

Background

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:

  1. A role that installs the Oracle JDK (ansible-java8)
  2. A role that installs Tomcat (ansible-tomcat7)

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

Questions

  1. Is this the correct way to define dependent roles or have I totally missed something?
  2. Am I correct in thinking that since I marked the tomcat7 role as depending on java8 that the java8 role should have been located from the roles_path and ran first?
  3. What mistake am I making that is causing the java8 role to not run before the tomcat7 role?
techraf
  • 64,883
  • 27
  • 193
  • 198
gregwhitaker
  • 13,124
  • 7
  • 69
  • 78
  • This works fine for me, can you confirm if your ansible.cfg has this? `[defaults] roles_path = ~/ansible/roles` – Mike D Dec 31 '15 at 03:46
  • 1
    also, your java8 role `meta/main.yml` is missing `dependencies: []`. this is causing `ansible-galaxy` to throw a non-critical error. – Mike D Dec 31 '15 at 03:55

1 Answers1

1

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' }
gregwhitaker
  • 13,124
  • 7
  • 69
  • 78