Member-only story
Rename file or directory — Ansible module copy and file
How to rename a file or directory foo, checking the file existence, and performing the verification in a live demo and some simple Ansible code.
How to rename a file or directory using an Ansible task on a remote system?
I’m going to show you a live demo with some simple Ansible code.
I’m Luca Berton and welcome to today’s episode of Ansible Pilot.
Ansible rename file/directory
First of all let me demystify that I’d like to propose a solution using only Ansible native modules, so no shell module to invoke the Unix utility `mv`.
Today we’re talking about Ansible two modules copy and file
The full names are ansible.builtin.copy and ansible.builtin.file which means are part of the collection of modules “builtin” with ansible and shipped with it.
Both are these modules are pretty stable and out for years.
The purpose of the `copy` module is to copy files to remote locations.
Once the file is successfully copied we could use the module `file` to delete the source file.