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.