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 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"

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like