简体   繁体   中英

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'] }

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM