[ansible-project] Re: Combinations of lists

2015-12-07 Thread Mike Biancaniello
have you tried ansible_nested (
http://docs.ansible.com/ansible/playbooks_loops.html#nested-loops)

Enter code here..---
- name: stuff
  hosts: localhost
  gather_facts: no
  connection: local

  vars:
l: [a,b,c]
n: [1,2,3]

  tasks:
- name: show nested
  debug: msg="[{{ item[0] }},{{ item[1] }}]"
  with_nested:
- l
- n
.

results in:
TASK: [show nested] 
***
ok: [localhost] => (item=['a', 1]) => {
"msg": "[a,1]"
}
ok: [localhost] => (item=['a', 2]) => {
"msg": "[a,2]"
}
ok: [localhost] => (item=['a', 3]) => {
"msg": "[a,3]"
}
ok: [localhost] => (item=['b', 1]) => {
"msg": "[b,1]"
}
ok: [localhost] => (item=['b', 2]) => {
"msg": "[b,2]"
}
ok: [localhost] => (item=['b', 3]) => {
"msg": "[b,3]"
}
ok: [localhost] => (item=['c', 1]) => {
"msg": "[c,1]"
}
ok: [localhost] => (item=['c', 2]) => {
"msg": "[c,2]"
}
ok: [localhost] => (item=['c', 3]) => {
"msg": "[c,3]"
}




On Monday, December 7, 2015 at 1:55:38 PM UTC-5, Chris Searle wrote:
>
> I get the feeling I'm missing something obvious - so feel free to tell me 
> so :)
>
> I seem to often want to do a combination of two lists - most often one 
> that is static and one that is dependent on the group.
>
> One example:
>
> I have a set of apache vhosts. So - I have a variable that has a list of 
> dicts - one per host. From that - I can create the htdocs dirs, log dirs, 
> the apache config files etc etc. This works fine.
>
> For apache I create the following directory structure per vhost:
>
> /srv/www/[fqdn]
> /srv/www/[fqdn]/htdocs
> /srv/www/[fqdn]/logs
>
> But - I also want to apply a standard set of extended attributes (using 
> acl) on the [fqdn], htdocs and logs dirs. So - for the standard set of 
> acl's I want to set - I have second (static) items list.
>
> I can't see how to apply each of the second list for each of the items in 
> the first list.
>
> Another example is managing a given list of four files for each of a set 
> of given directories - the files list is a static list, the directories 
> varies group to group.
>
> So - I was looking for something similar to with_together - but that 
> doesn't seem quite what I'm after.
>
> If I give with_together two lists like [a,b,c] and [1,2,3] I observe that 
> I get [a,1], [b,2] and [c,3].
>
> What I'm after is [a,1], [a,2], [a,3], [b,1], [b,2], [b,3], [c,1], [c,2] 
> and [c,3]
>
> What's the best way to approach this?
>
> Regards
>
> Chris
>

-- 
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/bab10510-c415-4cd0-97f0-9e54eb60e56f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Combinations of lists

2015-12-07 Thread Chris Searle
I cannot believe I missed that. Well - actually I can - I said I thought I 
was missing something obvious :)

I don't know how many times I read the with_nested docs without spotting it 
was _exactly_ what I needed - even by name. For some reason it just didn't 
register.

Many thanks - worked perfectly.

-- 
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/21529f23-235a-4a24-912a-3a78e872675a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.