On 06/11/2013 11:22, Jerome Wagner wrote:
> Hello,
Hey Jerome,
> I am also looking for a way to loop over a set of tasks.
[...]
> One option is to push the with_items down to the task level. This is
> what I did for my multi-versions installs but I did not need to register
> variables so it was simpler.
>
> The best would be to make a role loopable with minimum modifications
> (pushing with_items down to the tasks level is rather painful imho)
[...]
> The details would have to be refined but I think it could work to have
> the roles unroll as independent blocks of tasks rather than inside each
> task ; and if it works, it would look cleaner to me than obscuring the
> initial role with with_items and with_nested all over the place.
>
> Tell me if you try it !
That's hell of a hack, but it works like a charm (with few changes) !
$ cat roles/ruby/tasks/main.yml
---
# Common prereqs (e.g. build tools, libs)
- include: common-prereqs.yml
- include: rbenv-setup.yml
when: ruby.install
sudo: yes
sudo_user: "{{ ruby.deploy_user }}"
# Installing required ruby versions
- include: rbenv-install.yml ruby_version={{ version }}
when: ruby.install
sudo: yes
sudo_user: "{{ ruby.deploy_user }}"
....
$ cat roles/ruby-multi/meta/main.yml
---
dependencies:
- { role: ruby, version: "{{ versions[0] }}",
when: "0 < versions|length" }
- { role: ruby, version: "{{ versions[1] }}",
when: "1 < versions|length" }
- { role: ruby, version: "{{ versions[2] }}",
when: "2 < versions|length" }
....
Thanks a lot Jerome for the cool trick. Ask if you'd like the full
ruby/rbenv scoop.