Ansible - negate Filter

Stack Over picture Stack Over · May 19, 2017 · Viewed 9.3k times · Source

I find some files with the find ansible module

- find:
    paths: "/"
    patterns: ["*.service"]
    file_type: file
    hidden: True
    recurse: yes
  register: find_results
  when: ansible_service_mgr == "systemd"

Now I want to check modify the Permissions on some of the files:

- file:
    path: "{{ item.path }}"
    owner: root
    group: root
    mode: 0644
  with_items:
    - "{{ find_results.files }}"
  when:
    - item.path | match("/sys/devices/power/events/*")
    - ansible_service_mgr == "systemd"

The Problem is that I don't want a match. I want everything that don't match that path?

How can I negate the match filter? (!, not, etc.)?

Answer

Stack Over picture Stack Over · May 19, 2017

Thx for your help you can also do something like:

not (item.path | match("/sys/devices/power/events/*"))