My first thought was to put those two tasks into a block, modify task 1 to 
register a new variable that contains the current site
and use it in task 2. Then I remembered that you cannot loop over a block 
(currently…
https://github.com/ansible/ansible/issues/13262).


You could try to create a new list variable out of your dict which only 
contains all {{ site from dict }} and then use
with_nested. E.g.

- name: 'create docroot'
  ...

- name: 'extract sites'
  set_fact: sitenames='{{ sitenames | default([]) }} + {{ item.name }}'
  with_dict: '{{ sites }}'

- name: 'create symlinks'
  file:
    dest: '/var/www/html/{{ item[0] }}/{{ item[1] }}'
    src: '/var/www/grav/grav/{{ item[1] }}'
    state: link
    owner: www-data
    group: www-data
  with_nested:
    - '{{ sitenames }}'
    - [ 'bin', 'CHANGELOG.md', ...]






Am 28.08.2017 um 22:42 schrieb Michael Bushey:
> Thanks for responding Uwe! I appreciate your time. :)
> 
> I'm already using a with_dict to get the list of sites, but now for each site 
> I would like to provide a list of symlinks to
> generate. The list of symlinks does not change.
> 
> This creates the docroots:
> 
> - name: Create docroot
>   file: path=/var/www/html/{{ item.value.url }} state=directory 
> owner=www-data group=www-data
>   with_dict: "{{ sites }}"
>   when: item.value.type == "grav"
>   tags: grav, grav-sites
> 
> I would like to create the same symlinks for each of these sites, but I don't 
> know how to get {{ site from dict }}:
> 
> - name: Create symlinks
>   file: dest=/var/www/html/{{ site from dict }}/{{ item }} 
> src=/var/www/grav/grav/{{ item }} state=link owner=www-data group=www-data
>   with_items:
>     - bin
>     - CHANGELOG.md
>     - composer.json
>     - .editorconfig
>     - .gitignore
>     - index.php
>     - LICENSE.txt
>     - system
>     - vendor
>   tags: grav, grav-sites
> 
> 
> On Mon, Aug 28, 2017 at 12:52 PM, Uwe Sauter <[email protected] 
> <mailto:[email protected]>> wrote:
> 
>     I'm not quiet sure I understand your data model but instead of with_items 
> have a look at with_dict.
> 
>     Am 28.08.2017 um 21:51 schrieb Michael Bushey:
>     > Hello,
>     >
>     > I have a dict that contains a list of sites. For each of these sites I 
> would like to provide a list of symlinks to
>     > create provided by with_items. Is this possible? I have Ansible 2.3.1.0.
>     >
>     >
>     > Thanks!
>     > Michael
>     >
>     > --
>     > 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
>     > [email protected] 
> <mailto:ansible-project%[email protected]>
>     <mailto:[email protected] 
> <mailto:ansible-project%[email protected]>>.
>     > To post to this group, send email to [email protected] 
> <mailto:[email protected]>
>     <mailto:[email protected] 
> <mailto:[email protected]>>.
>     > To view this discussion on the web visit
>     > 
> https://groups.google.com/d/msgid/ansible-project/13eb2739-7e21-4503-8e75-7f3db8803966%40googlegroups.com
>     
> <https://groups.google.com/d/msgid/ansible-project/13eb2739-7e21-4503-8e75-7f3db8803966%40googlegroups.com>
>     >
>     
> <https://groups.google.com/d/msgid/ansible-project/13eb2739-7e21-4503-8e75-7f3db8803966%40googlegroups.com?utm_medium=email&utm_source=footer
>     
> <https://groups.google.com/d/msgid/ansible-project/13eb2739-7e21-4503-8e75-7f3db8803966%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>     > For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
> 
>     --
>     You received this message because you are subscribed to a topic in the 
> Google Groups "Ansible Project" group.
>     To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/ansible-project/gns-XRtt9aE/unsubscribe
>     
> <https://groups.google.com/d/topic/ansible-project/gns-XRtt9aE/unsubscribe>.
>     To unsubscribe from this group and all its topics, send an email to 
> [email protected]
>     <mailto:ansible-project%[email protected]>.
>     To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
>     To view this discussion on the web visit
>     
> https://groups.google.com/d/msgid/ansible-project/d8d85ea0-addc-6d99-c3ad-be9bfc62f83d%40gmail.com
>     
> <https://groups.google.com/d/msgid/ansible-project/d8d85ea0-addc-6d99-c3ad-be9bfc62f83d%40gmail.com>.
>     For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
> 
> 
> -- 
> 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 [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAPJTyAXqsGF7HMoF5fNjaacL%2Bfsxz%3D9dZ%3DhHR6K7THF%2B74QhTg%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAPJTyAXqsGF7HMoF5fNjaacL%2Bfsxz%3D9dZ%3DhHR6K7THF%2B74QhTg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d0e76321-23b3-190c-4e6c-c54641d1ffb1%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to