Reputation: 63
I am trying to find files with .ign extension from a directory and copy it to another directory. Tried using the 'find' and 'copy' module as follows:
- name: Find files
find:
paths: "{{ item }}"
recurse: yes
register: find_result
with_items:
- "{{ workdir }}/*.ign"
- name: Copy files
copy:
src: "{{ item.path }}"
dest: "/var/www/html/ignition/"
mode: o+r
remote_src: yes
with_items: "{{ find_result.files }}"
workdir
is set as /root/openstack-upi
. And I am running this as a non-root(cloud-user) user with the command--
ansible-playbook -i inventory -e @install_vars.yaml playbooks/install.yaml --become
However, after running this I get an error as below:
TASK [ocp-config : Find files] ***************************************************
ok: [ash-test-faf0-bastion-0] => (item=/root/openstack-upi/*.ign)
TASK [ocp-config : Copy files] ***********************************************
fatal: [ash-test-faf0-bastion-0]: FAILED! => {"msg": "'dict object' has no attribute 'files'"}
PLAY RECAP **********************************************************************************
ash-test-faf0-bastion-0 : ok=3 changed=0 unreachable=0 failed=1 skipped=1 rescued=0 ignored=0
Running a debug on variable find_result
gives the following-
"msg": "/root/openstack-upi/*.ign was skipped as it does not seem to be a valid directory or it cannot be accessed\n"
Am I missing anything here? Can anybody tell me the exact command for the ansible-playbook for the above scenario?
Upvotes: -1
Views: 2012
Reputation: 488
The following solution will does not use the with_items
option. It will recursively find all the files which ends with the extension/suffix .ign
.
- name: Find files
find:
paths: "/path/to/directory"
patterns: "*.ign"
recurse: yes
register: result
- name: Print find result
debug:
msg: "{{ item.path }}"
with_items:
- "{{ result.files }}"
Upvotes: 2