I need to identify a set of files in a directory and rename all those with a .repo extension. Is it possible to do it with native Ansible functions? If it's not possible I'll use a pure and hard shell command.
1 Answer
As to this answer ansible does not support move / rename functionality: https://stackoverflow.com/questions/24162996/how-to-move-rename-a-file-using-an-ansible-task-on-a-remote-system
If you're careful with fileglob you can workaround not using shell like this:
---
- name: copy files to new names and remove old ones
hosts: all
become: yes
tasks:
- name: copy all .repo files in a spec. directory to new names
copy:
src: "{{ item }}"
dst: whatever_you_want_me_to_be_{{ item }}.reponot
with_fileglob: "/tmp/repofiles/*repo"
- name: remove all .repo files in a spec. directory
file:
path: "{{ item }}"
state: absent
with_fileglob: "/tmp/repofiles/*repo"