Rename a File with Native Ansible Functions
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...
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:
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"