ansible-fprobe/tasks/immutable.yml

29 lines
770 B
YAML
Raw Normal View History

---
## manage install when some directories are immutable
## requires target_dir, state=pre/post
- block:
## Ansible 2.3+ for get_attributes
- name: check target_dir {{ target_dir }} attributes
# stat:
# path: "{{ target_dir }}"
# get_attributes: yes
command: "lsattr -d '{{ target_dir }}'"
register: dir
changed_when: false
ignore_errors: true
- name: Remove immutable attribute
command: "chattr -i '{{ target_dir }}'"
ignore_errors: true
when: dir.stdout.find('-i-') != -1
when: state == 'pre'
- name: Reestablish immutable attribute
command: "chattr +i '{{ target_dir }}'"
# file:
# dest: "{{ target_dir }}"
# attributes: '----i-----I--e--'
when: state == 'post'
ignore_errors: true