conditional roles

93 views
Skip to first unread message

Yves Dorfsman

unread,
May 13, 2013, 12:23:24 PM5/13/13
to ansible...@googlegroups.com

Is this normal/expected?

I am trying to use conditional roles, and once it hits a negative condition,
it skips every role afterwards:


- hosts: all
roles:
- common
- role: AppDynamics
when: appdynamics
- java

"appdynamics" is loaded as True/False from a group_vars, and is different
depending on the environment loaded (different inventories, group_vars etc...
for PROD vs. TEST vs. DEV).

With the playbook above, the java role is skipped when appdynamic is False. If
I move the java role above the AppDynamics role, then the java role never gets
skipped.

Should the condition affect roles after it?


Thanks.

--
Yves. http://www.SollerS.ca/
Unix/Linux and Python specialist in Calgary.
http://blog.zioup.org/

Michael DeHaan

unread,
May 13, 2013, 1:26:03 PM5/13/13
to ansible...@googlegroups.com
I'm not sure you're seeing what behavior you think you are seeing.

When just applies the conditional to each task.

It's also a confusing (and noisy output) way to organize things, which is why we don't encourage it.

it's much better to do this:

- hosts: AppDynamics
  roles:
     - AppDynamics





--
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.
For more options, visit https://groups.google.com/groups/opt_out.





--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

David Reagan

unread,
Mar 14, 2014, 10:32:25 PM3/14/14
to ansible...@googlegroups.com
I was just looking to do the same thing. Michael's post clued me into what I was missing.

Specifically, I hadn't realized you can list your hosts more than once in the hosts file. That makes a site.yml file similar to:

- hosts: roleA
  roles:
    - roleA

- hosts: roleB
  roles:
    - roleB


Work to give you the same effect as we wanted with conditional roles. Just list the host under all the roles you want it to have in the groups file.

Thanks Michael!
Reply all
Reply to author
Forward
0 new messages