Referencing roles within a module?

40 views
Skip to first unread message

josp...@redhat.com

unread,
Aug 23, 2017, 8:04:06 AM8/23/17
to Ansible Project
First off, I am pretty new to Ansible roles, so please bear with me. There is a set of roles in a module (https://github.com/redhat-cop/casl-ansible), and I want to use a role within that module called `oc-apply`. How do I reference that?

I created a YAML file to install the module:

# This is the Ansible Galaxy requirements file to pull in the correct roles
# to support the operation of CASL provisioning/runs.
- src: https://github.com/redhat-cop/casl-ansible

  scm
: git
  version
: master


And a playbook which is wanting to use the `oc-apply` role within that module

---
- hosts: localhost
  roles
:
 
- casl-ansible/oc-apply


Then I installed the module using galaxy

ansible-galaxy install --roles-path . -r casl-ansible.yml


But I cannot seem to figure out how to properly reference the role inside of `casl-ansible`. Any suggestions would be appreciated!!!

Cheers,

Deven

josp...@redhat.com

unread,
Aug 23, 2017, 8:27:10 AM8/23/17
to Ansible Project
I found a work-around, but I am not sure if it is the correct way to handle this.

After installing via ansible-galaxy as described above, I used the following playbook to run the role:

---
- hosts: localhost
  roles
:

 
- { role: 'casl-ansible/roles/oc-apply' }


Anyone have a better solution?

Thanks,

Deven

Soniya panwar

unread,
Aug 23, 2017, 2:26:46 PM8/23/17
to Ansible Project
yes, you are doing this in right way, you can call role directly or you can parameterize the roles:
Example:
---
- hosts: localhost
  roles:
   - casl-ansible/roles/oc-apply
 - { role: casl-ansible/roles/oc-apply }
or if you wants to use any condition or variable to execute your role then you can parameterise your roles like this:
---
- hosts: localhost
  roles:
  - { role: casl-ansible/roles/oc-apply, when: <"ansible_os_family == 'RedHat'"> }
Reply all
Reply to author
Forward
0 new messages