Trying to update an immutable file (on a filesystem that supports attributes) with Ansible fails with the following error.
Operation not permitted
Also see https://github.com/ansible/ansible/issues/48886
Example Task
- name: example
template:
src: example.j2
dest: /some/example
attributes: '+i'
So far I have come up with the following options to handle this, each with a drawback.
Option 1)
drawback: both tasks always change the file on every run
- name: Make example mutable (so changes can be applied)
file:
path: /some/example
attributes: '-i'
- name: Deploy example
template:
src: example.j2
dest: /some/example
attributes: '+i'
Option 2)
drawback: the initial error is shown which might be confusing and it has code duplication
- name: Handle example changes
block:
- name: Deploy example
template:
src: example.j2
dest: /some/example
attributes: '+i'
rescue:
- name: Make example mutable (so changes can be applied)
file:
path: /some/example
attributes: '-i'
- name: Deploy example
template:
src: example.j2
dest: /some/example
attributes: '+i'
So how should a task like this be implemented to successfully apply changes without any error?