0

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

1 Answer 1

1

Ok, solved it :)

Here the task for everyone who intends to do the same.

Only the skip/changed console output could be replaced by a nicer message.

- 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.item}}"
    state: touch
    mode: u-x,g-x,o-x
  with_items: "{{ filecheck.results }}"
  when: item.stat.exists == true and item.stat.executable == True

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.