I am scratching my head to why my code is not registering files in the dict
something wrong with my code in the playbook but cannot see what
vars:
file_vars:
- { spath: /var/log/ctm, type: file, mode: o-w, pattern: "^.*?\\.(?:sh|fp|so|xml)$" }
tasks:
- name: Find files depending on REGEX pattern
find:
paths: "{{ item.spath }}"
file_type: "{{ item.type }}"
recurse: yes
patterns: "{{ item.pattern }}"
use_regex: yes
with_items:
- "{{ file_vars }}"
register: change_mode
- debug:
var: change_mode
- name: remove world writable permissions
file:
path: "{{ item.path }}"
mode: o-w
with_items:
- "{{ change_mode.files }}"
FAILED! => {"msg": "'dict object' has no attribute 'files'"}
any help greatly appreciated
Best Answer
If you read the output of your task
debug
you'd noticechange_mode
is a dictionary containingresults
list, and notfiles
. That's because of thewith_items
loop in yourFind files depending on REGEX pattern
task.Iterate over
change_mode.results
with subelementsfiles
:With your current data the loop in
Find files depending on REGEX pattern
task in unnecessary, so you can just remove it, but I assume you wantfile_vars
to be extendible.