SPR
SPR

Reputation: 15

Ansible Could not find or access

I'm trying to make loop with 2 lookup(fileglob) in my task

---
- hosts: localhost
  become: yes
  become_user: root

  tasks:

    - name: Loop with 2 lookup
      copy:
        src: '{{ item.src }}'
        dest: '{{ item.dest }}'
      loop: 
        - { src: "{{ lookup('fileglob', 'custom_scripts/*', wantlist=True) }}",  dest: /var/custom_scripts/ }
        - { src: "{{ lookup('fileglob','certs/*', wantlist=True) }}", dest: /var/custom_certs/ }

When i try to run this i get Could not find or access "path to files" in error log ansible is seeing all this files, because is listing all files which can't access. Permissions for all folders and files are set on 777

Upvotes: 1

Views: 3467

Answers (1)

seshadri_c
seshadri_c

Reputation: 7350

This logic to copy files seems to be flawed, and most likely causing this issue. item.src as you are trying to access, is a list (wantlist=True). In effect, you are passing a list of files to the src parameter of copy, and not 1 file.

Also, the copy module supports copying entire directories. So there should be no need to actually get the list of files.

A task such as below should do it:

    - name: Loop with 2 lookup
      copy:
        src: '{{ item.src }}'
        dest: '{{ item.dest }}'
      loop: 
        - { src: 'custom_scripts/', dest: '/var/custom_scripts' }
        - { src: 'certs/', dest: '/var/custom_certs' }

Upvotes: 1

Related Questions