Bhavik Bhavsar
Bhavik Bhavsar

Reputation: 301

How to Include task from another role in ansible?

I want to include a task from a different role.

I would not want to hardcode it like

- name : Set topology based on Jenkins job name
  include: ../../pre-req/tasks/set-topo.yml
  tags: core

Is there a way to do this with dependency? I tried creating a meta directory with files and tasks, somehow it' s not getting triggered.

something like this

vim roles/pre-req/meta/main.yml

---
allow_duplicates: yes
dependencies:
  - { role: topo, tags: ['core'] }

Upvotes: 1

Views: 4144

Answers (1)

Xiong Chiamiov
Xiong Chiamiov

Reputation: 13754

I would not want to hardcode it like

Why not? You want to include a task, and that's how you include a task.

If what you want to do is include the entire other role, Ansible 2.2 (released yesterday) added include_role.

Upvotes: 2

Related Questions