For several modules, Ansible has a backup option.
- name: template a file w backup option
template:
src: my_file.j2
dest: /tmp/
backup: true
Each time Ansible runs, and there is a change for that file, Ansible creates a backup file in the respective folder. In the end, there will be many backup files.
Q: Is there an elegant Ansible solution to remove these backup files for which it placed the file/template? E.g. keep only the latest 3 backup files?