I'd like to remove the execute bit from some ubuntu motd (Message of the day) files with ansible to disable some ad-like Ubuntu news. The module should only act if files exist and permissions are wrong.
If there are no files the tasks are running fine, but as soon as a file exists, I'm getting this:
Error Message:
failed: [ip] (item={'_ansible_parsed': True, u'stat': {u'isuid': False, u'uid': 0, u'exists': True, u'attr_flags': [... redacted the rest of the file attributes from stat ...]
Mayboe someone can help?
Here the files of my role:
defaults/main.yml
---
motd_path: '/etc/update-motd.d'
unwanted_motd_files:
- 10-help-text
- 50-motd-news
tasks/main.yml
---
- name: Register unwanted motd files
stat:
path: "{{motd_path}}/{{item}}"
register: filecheck
with_items: "{{ unwanted_motd_files | default([]) }}"
- name: Check if unwanted motd files are executable and remove the executable bit
file:
path: "{{motd_path}}/{{ item }}"
state: touch
mode: u-x,g-x,o-x
with_items: "{{ filecheck.results }}"
when: item.stat.exists == true