On Wed, 04 Feb 2015 16:38 -0800, Chip Selden <chipsel...@gmail.com>
wrote:
> Suraj,
> 
> I've been trying to find a way to do this as well, with no luck so far.
> 
> Ideally, I'd be able to use a loop (either with_items, or with_dict) to
> run 
> multiple and differing roles on a per-host basis. But, alas, this is not
> a 
> feature and from what I can find from older posts, will not be a feature. 
> Passing in a list variable to "roles:" is a good idea, but it doesn't
> seem 
> like Ansible can use variables (even extra-vars from the ansible-playbook 
> command) to determine which roles are to be used.

If I understand it, there is a need to run a playbook and it would apply
a different set of roles to different set of roles, right?

My suggestion is to define many plays per playbook. You'd not be
defining a "roles" variable to be imported and, sure, there is more
typing involved but it's clean and works:


---
- name: Provision web layer
  hosts: webservers
  sudo: yes
  roles:
    - common
    - nginx

- name: Provision db layer
  hosts: dbservers
  sudo: yes
  roles:
    - common
    - mariadb


The reason defining a list somewhere else (say, group_vars/webservers)
does not work is because it's becomes a dictionary ("web_roles -> {
roleA, roleB }") and the "roles" parameter in a play expects a list.

Just so I understand this better, would there be any issue with defining
multi-play playbooks? What's exactly the use case in your scenario?
People with access to change only vars files or perhaps the need to feed
the role list dynamically? What are you trying to achieve? :)

Giovanni

-- 
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+unsubscr...@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/1423132299.263197.223413473.47DF307F%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to