I worked it out ...
vars :-
-------
# Instances
acs_dmz_deploy_instances:
- name: 'test1'
config_dir: '/opt/www/test1'
java_version: 'java-1.8.0-openjdk-headless'
user: "tomcat"
group: "tomcat"
mode: "0644"
acs_dmz_deploy_config_file_copy_only: true
files:
- { src: 'file1', dest: '/opt/www/test1'}
- { src: 'file2', dest: '/opt/www/test1'}
- name: 'test2'
config_dir: '/opt/www/test2'
java_version: 'java-11-openjdk-headless'
user: tomcat9
group: tomcat9
mode: "0644"
acs_dmz_deploy_config_file_copy_only: false
files:
- { src: 'file3', dest: '/opt/www/test2'}
-------
copy task :
------
- name: Copy config files
copy:
src="../../../../configs/acs-dmz/{{ item.0.name }}/{{ item.1.src }}"
dest="{{ item.1.dest }}/"
owner="{{ item.0.user }}"
group="{{ item.0.group }}"
mode="{{ item.0.mode }}"
loop: "{{ acs_dmz_deploy_instances | subelements('files') }}"
when: "item.0.acs_dmz_deploy_config_file_copy_only == true"
------
On Tuesday, 24 May 2022 at 20:16:46 UTC+1 morgan cox wrote:
> Hi.
>
> Having an issue with a seemingly simple task, I just cannot work this out,
> pretty sure there is a simple way of doing this ...
>
> I have these example vars for a role
> --------
> acs_deploy_instances:
> - name: 'test1'
> config_dir: '/opt/www/test1'
> java_version: 'java-1.8.0-openjdk-headless'
> files:
> - 'file1'
> - 'file2'
> - name: 'test2'
> config_dir: '/opt/www/test2'
> java_version: 'java-11-openjdk-headless'
> files:
> - 'file3'
> - 'file4'
> --------
>
> I am trying to copy local files inside the configs dir in the server
> profile i.e
>
> servers/server1/configs/acs/test1/file1
> servers/server1/configs/acs/test1/file2
>
> to the folder specified in acs_deploy_instances.config_dir
>
> I can see the files correctly if I do
>
> ----
> - debug:
> msg: "{{ item.files }}"
> with_items: "{{ acs_dmz_deploy_instances }}"
> ----
>
> Output :
>
> TASK [common/acs-dmz-deploy : debug]
> *******************************************
> ok: [localhost] => (item={'name': 'test1', 'config_dir': '/opt/www/test1',
> 'java_version': 'java-1.8.0-openjdk-headless', 'files': ['file1'
> , 'file2']}) => {
>
>
>
> "msg": [
> "file1",
> "file2"
> ]
> }
> ok: [localhost] => (item={'name': 'test2', 'config_dir': '/opt/www/test2',
> 'java_version': 'java-11-openjdk-headless', 'files': ['file3', '
> file4']}) => {
>
>
>
> "msg": [
> "file3",
> "file4"
> ]
> }
>
> ---
>
> The issue is the fact the src files are in a 'sub list' - i.e file1/file2
> so when i try to do this task to copy these files it will not work as the
> output contains multiple values (and square brackets)
>
> Example task :
>
> ----
> - name: Copy config files
> copy:
> src="../../../../configs/acs/{{ item.name }}/{{ item.files }}"
> dest="{{ item.config_dir }}/"
> owner="root"
> group="root"
> mode="0644"
> with_items: "{{ acs_dmz_deploy_instances }}"
> ----
>
> I get the error
>
> "msg": "Could not find or access '../../../../configs/acs/test1/['file1',
> 'file
> 2']'\nSearched
> in:\n\t/etc/ansible/roles/common/acs-dmz-deploy/files/../../../../configs/acs/test1/['file1',
>
> 'file2']\n\t/etc/ansible/roles
> /common/acs-dmz-deploy/../../../../configs/acs/test1/['file1',
> 'file2']\n\t/etc/ansible/roles/common/acs-dmz-deploy/tasks/files/../../../..
> /configs/acs/test1/['file1',
> 'file2']\n\t/etc/ansible/roles/common/acs-dmz-deploy/tasks/../../../../configs/acs/test1/['file1',
>
> 'file2']\n\
> t/etc/ansible/files/../../../../configs/acs/test1/['file1',
> 'file2']\n\t/etc/ansible/../../../../configs/acs/test1/['file1', 'file2']
> on th
> e Ansible Controller.\nIf you are using a module and expect the file to
> exist on the remote, see the remote_src option"}
> An exception occurred during task execution. To see the full traceback,
> use -vvv. The error was: If you are using a module and expect the f
> ile to exist on the remote, see the remote_src option
>
>
> Can anyone suggest a way to copy the files in the 'sub list' to the
> 'config_dir' var ?
>
> I've tried using loops, etc but nothing so far is working
>
>
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/69dfc451-40ef-4306-9649-eb1e0cf47c96n%40googlegroups.com.