I'm trying to get the following Ansible playbook to work but cannot figure out how to tell Ansible to either:
Here's my code:
- name: Install prerequisite roles
hosts: all
become: no
tasks:
- name: run ansible galaxy
local_action: command ansible-galaxy install -r requirements.yml -p roles/
- name: Install Oracle Java
hosts: tomcat-servers:ss-servers:ns-servers:ld-servers
become: yes
roles:
- raltd-jdk
I tried doing the above using pre_tasks as well and that didn't work either. My requirements.yml is simply this:
- src: [email protected]:ansible/raltd-jdk.git
scm: git
I'm getting this error:
$ ansible-playbook -i inv/myinventory raltd-jdk.yml
ERROR! the role 'raltd-jdk' was not found in /path/to/ansible/roles:/etc/ansible/roles:/path/to/ansible
The error appears to have been in '/path/to/ansible/raltd-jdk.yml': line 16, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
roles:
- raltd-jdk
^ here
I received the following response from the Ansible dev team.
@slmingol this particular error is by design. Roles and tasks are preloaded before any of them are executed. We have ongoing proposals that tackle this problem from different angles, but none of them have yet to be accepted or written.
He also referenced this proposal: Proposal: Auto Install Ansible Roles
To use the latest (or even a specific) version of a playbook with the appropriate roles, the following steps are typically required:
git pull upstream branch ansible-galaxy install -r path/to/rolesfile.yml -p path/to/rolesdir -f ansible-playbook run-the-playbook.ymlThe most likely step in this process to be forgotten is the middle step. While we can improve processes and documentation to try and ensure that this step is not skipped, we can improve ansible-playbook so that the step is not required.
So it would appear this isn't possible until this proposal gets implemented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With