Add role dependency to another role without it being executed automatically

47 views
Skip to first unread message

Lee Connell

unread,
Jul 7, 2017, 3:08:06 PM7/7/17
to Ansible Project
Hi all,

I have a role that has a dependency on another role, however by default, Ansible will execute the dependency first. In my case, I do not want this to happen. I don't want the role executed automatically at all. The role that is requiring this dependency will call it on its own within it's own tasks.  Right now, I am checking if a variable is defined, and if it is, then the tasks within the dependent role will run, but you still see the task line item in the playbook output. I would like to avoid it attempting to execute it altogether.



Dick Davies

unread,
Jul 7, 2017, 4:22:18 PM7/7/17
to ansible list
It doesn't sound like you want a dependency at all.

Why not just stick the slack tasks in the relevant roles?
You're losing a lot of clarity trying to use a role to save a bit
of typing, and from the look of that gist you aren't even saving
much typing :)
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/82198539-1af4-4885-8254-ae9788b9d85b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Lee Connell

unread,
Jul 9, 2017, 12:07:04 PM7/9/17
to ansible...@googlegroups.com
I agree, I'm going to move them into the roles, especially since the slack role doesn't really accomplish much.

With that being said, say the dependent role was a bunch of API calls to accomplish some task. In this case, I could call include role and call for a particular task within that role. 

If I added it as a dependency to my calling role, I would end up in the same position. Am I just using Ansible and roles, the wrong way here?

How can you add a role as a dependency without it being called by default? Seems like that isn't possible. Any alternative approaches?

Thanks for your response  :)

On Jul 7, 2017 4:22 PM, "Dick Davies" <di...@hellooperator.net> wrote:
It doesn't sound like you want a dependency at all.

Why not just stick the slack tasks in the relevant roles?
You're losing a lot of clarity trying to use a role to save a bit
of typing, and from the look of that gist you aren't even saving
much typing :)

On 7 July 2017 at 20:08, Lee Connell <lee.a....@gmail.com> wrote:
> Hi all,
>
> I have a role that has a dependency on another role, however by default,
> Ansible will execute the dependency first. In my case, I do not want this to
> happen. I don't want the role executed automatically at all. The role that
> is requiring this dependency will call it on its own within it's own tasks.
> Right now, I am checking if a variable is defined, and if it is, then the
> tasks within the dependent role will run, but you still see the task line
> item in the playbook output. I would like to avoid it attempting to execute
> it altogether.
>
> https://gist.github.com/lconnell/dfb1dc5383517b3bdd9c4832ae9027e2
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-project+unsubscribe@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/A_-BJFtygS8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAK5eLPTNcibS6t92e1rEm%3DYiAqV6GvfYU0h66fDrw4tehT0NFQ%40mail.gmail.com.

Maciej Delmanowski

unread,
Jul 9, 2017, 12:09:36 PM7/9/17
to ansible...@googlegroups.com
Just add it in the playbook. Ansible reads all roles on the playbook level and includes their variables, the same as a role dependency in `meta/main.yml`. That way you can run the specific roles using tags without executing the dependencies as well.

Lee Connell

unread,
Jul 9, 2017, 2:45:44 PM7/9/17
to ansible...@googlegroups.com
Right, that's what I was originally doing and works just fine. My thought process whas to add it as a dependency so it would get installed via the galaxy command automatically. Without the role added as a dependency, it will need to be a manual process.

Thanks!

Reply all
Reply to author
Forward
Message has been deleted
0 new messages