Check with_subelements loop. This is solution to your problem.

Krzysztof Ząbkowski

http://docs.ansible.com/playbooks_loops.html#looping-over-subelements

W dniu poniedziałek, 13 kwietnia 2015 14:12:21 UTC+2 użytkownik 
[email protected] napisał:
>
> Hi, I am trying to create a role for multiple installations of apache on 
> one host.
>
> *My group_vars:*
> apache:
>   - { name: vhost1,
>       dir: installation1,
>     ...lot of other variables...
>       file:
>         - { src: /deploy/1.txt, dst: /tmp/1.txt }
>         - { src: /deploy/2.txt, dst: /tmp/2.txt }
>     }
>
>   - { name: vhost2,
>       dir: installation2,
>     ...lot of other variables...
>       file:
>         - { src: /deploy/3.txt, dst: /tmp/3.txt }
>     }
>
> *Task with problem:*
>
> - name: copy files
>   copy: src={{ item.file.src }} dest={{ item.file.dst }}
>   with_items: apache
>
>
> *Error:*
> ERROR: Syntax Error while loading YAML script, /roles/apache/vars/main.yml
> Note: The error may actually appear before this position: line 39, column 9
>
>       file:
>         - { src: /deploy/1.txt, dst: /tmp/1.txt }
>
> *I try:*
> *My group_vars:*
> apache:
>   - name: vhost1
>     dir: installation1
>    ...lot of other variables...
>     file:
>       - { src: /deploy/1.txt, dst: /tmp/1.txt }
>       - { src: /deploy/2.txt, dst: /tmp/2.txt }
>     
>
>   - name: vhost2
>     dir: installation2
>    ...lot of other variables...
>     file:
>       - { src: /deploy/3.txt, dst: /tmp/3.txt }
>
> *Task with problem:*
>
> - name: copy files
>   copy: src={{ item.file.src }} dest={{ item.file.dst }}
>   with_items: apache
>
> *Error:*
> fatal: [test] => One or more undefined variables: 'list object' has no 
> attribute 'src'
>
>
> *and also try:My group_vars*
> apache:
>   - name: vhost1
>     dir: installation1
>    ...lot of other variables...
>     file:
>       - src: /deploy/1.txt
>         dst: /tmp/1.txt
>       - src: /deploy/2.txt
>         dst: /tmp/2.txt 
>     
>   - name: vhost2
>     dir: installation2
>    ...lot of other variables...
>     file:
>       - src: /deploy/3.txt 
>         dst: /tmp/3.txt
>
> *Task with problem:*
>
> - name: copy files
>   copy: src={{ item.file.src }} dest={{ item.file.dst }}
>   with_items: apache
>
> *Error:*
> fatal: [test] => One or more undefined variables: 'list object' has no 
> attribute 'src'
>
> How can I solve my problem? Depending on my needs, I need to have in the 
> variable "file" specification of one or more files to be copied.
>

-- 
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/a98e1d9b-6edd-4048-8ff4-d50debb3a9d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to