Role Dependencies - Only Run Tag of Dependent Role

146 views
Skip to first unread message

Jacob Seeley

unread,
Jul 2, 2015, 9:46:21 AM7/2/15
to ansible...@googlegroups.com
Hello,

I'd like to have one role be dependent upon another role's tag only. Here is what I am trying:

# meta/main.yml

---

dependencies:
  - { role: common }
  - { role: other_role, tags: ['other_role_autofs'] }

Expected Behaviour

All tasks in the role common are run
Only the role other_role' task with a tag of other_role_autofs is run

Actual Behaviour

All tasks in the role common are run
All tasks in the role other_role are run

Strahinja Kustudić

unread,
Jul 2, 2015, 9:52:27 AM7/2/15
to ansible...@googlegroups.com
Ansible doesn't support role dependency using tags. Tags are only used for executing specific tasks which can be passes from the command line.

To do what you want, you would have to define a variable in the other_role and set a when: clause on all tasks when that variable is true, or set.

Jacob Seeley

unread,
Jul 2, 2015, 10:15:54 AM7/2/15
to ansible...@googlegroups.com
That's unfortunate. That would require me to set variables in all tasks on other_role that I would not have otherwise set, just so that I can pass a variable that triggers one task in other_role.

Strahinja Kustudić

unread,
Jul 2, 2015, 10:17:43 AM7/2/15
to ansible...@googlegroups.com
What you could do is group those task into a separate yml file and then include them in the main.yml:

include: some_var_tasks.yml
when: some_var

Jacob Seeley

unread,
Jul 2, 2015, 10:26:23 AM7/2/15
to ansible...@googlegroups.com
Well, I'm already doing that inside other_role; however, I'm guessing if I make other_role a dependency of this other role and pass some_var, it's still going to try to execute all other tasks in other_role, including all other ones defined in their own yml and included in other_role main.yml

Unless you're suggesting I somehow include this yml file that exists in other_role in the main.yml of the role that is dependent upon this task.

And to be clear, I'm trying to make this happen so that I don't have to recreate this task in this other role.

Strahinja Kustudić

unread,
Jul 2, 2015, 10:39:53 AM7/2/15
to ansible...@googlegroups.com
I think I lost you now. If you could give us the role structure, dependencies and what you would like to achieve, I think it will be easier to help you out.

Jacob Seeley

unread,
Jul 2, 2015, 11:06:11 AM7/2/15
to ansible...@googlegroups.com
I was afraid of that. I'll start fresh.

role1/
├── files
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
└── tasks
    ├── task1.yml
    ├── task2.yml
    ├── main.yml
    └── task3.yml
   
role2/
├── files
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
└── tasks
    ├── task1.yml
    ├── task2.yml
    ├── main.yml
    └── task3.yml

# role2/meta/main.yml

---

dependencies:
  - { role: role1, but only task1.yml of role1 and nothing else. }

I was trying to accomplish using tags, as I have task1.yml role1 tagged, but you say this isn't possible. I need to call role1's task1.yml as a dependency within role2, not the entire role1.
Reply all
Reply to author
Forward
0 new messages