I already know how do move or rename a file. I’m just wondering why there isn’t a specific module that does this. It seems like a very specific design decision… does anyone know what the reason was?
Although I have no direct insights in this, my opinion on why there is no move/rename module is that such operations would intrinsically be non-idempotent. Although Ansible has no strict rule against non-idempotent code, there has always been a strong bias against it.
5 Likes
If you know unix and the ansible.builtin.file module, you could have found the link optioin. In unix, a rename and a move within a filesystem is effective a hardlink on the new location and a removal on the old location. With the ansible.builtin.file module you can do the same.
Following https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html:
- name: Create the new name
ansible.builtin.file:
src: /path/to/old/name
dest: /path/to/new/name
state: hard - name: Remove the old name
ansible.builtin.file:
path: /path/to/old/name
state: absent
2 Likes