On 20/01/14 13:48, Michael DeHaan wrote:
> I should also add, the above is not a hack.
>
> It's encouraged syntax :)
>
> roles:
> - { role: setup_users, users: "{{ my_users }}" }
>
Possibly I didn't explain what I meant by the "hack" very well: I meant
the one Jerome Wagner suggested which uses a 'loop' wrapper role with
the capability to repeat another named role N times (up to some bound
M), by supplying a list of N sets of parameters to pass. The role has M
invocations of that role, each of which is guarded by a conditional
which skips it unless there is a corresponding element in the list.
To quote:
> Let's say you have you role : "ruby_install_one_version"
>
> Now you define a new role "loop"
> - { role: "loop", over: "ruby_install_one_version", iconf: [ {
> version: "1.9.3-p448"}, { version: "2.0.0-p247" } ] }
>
> in meta.main.yml / dependency, you add something like (I still have a
> hard time with $ and {{}} in these contexts and I am not sure .length
> is the way to do it)
>
> - { role: "{{ over }}", conf: $iconf[0], when: "0 < iconf.length" }
> - { role: "{{ over }}", conf: $iconf[1], when: "1 < iconf.length" }
> - { role: "{{ over }}", conf: $iconf[2], when: "2 < iconf.length" }
> - { role: "{{ over }}", conf: $iconf[3], when: "3 < iconf.length" }
> - { role: "{{ over }}", conf: $iconf[4], when: "4 < iconf.length" }
Does Jerome's work-around fall foul of the limitation you mention? i.e.
That:
> ...the role must be applied in the same definition (but not the same
> variables) to each host in the host group. Ergo, you can't have
> different numbers of roles applied to different hosts in the same
> group based on some kind of inventory variance.
If so, I'm curious to know in case I need to resort to this solution. I
would suspect that there would be no problem, since the parameters are
supplied directly to the role and not implicitly taken from the
host_vars/group_vars, but perhaps I'm not understanding something.
If not, couldn't there be an in-core Ansible solution which works
essentially the same way (but without the upper bound)?
Cheers,
N