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/e055cc3b-d38c-4f47-bdbb-c86961ad09dbn%40googlegroups.com.

Reply via email to