- name: find config files
find:
paths: "/directory/files/"
patterns: "*.yaml,*.yml"
register: yaml_files
I just want to run command when the file contains "kind: Namespace", but this will run with all the file found.
Try search
- name: Create namespace first
command: "{{ bin_dir }}/kubectl apply -f {{ item }}"
loop: "{{ yaml_list }}"
when: lookup('file', item) is search('kind\:\ Namespace')
(not tested)
- name: find config files
command: 'find /directory/files/ -type f \( -iname \*.yml -o -iname \*.yaml \)'
register: yaml_files
- name: Create namespace first
command: 'kubectl apply -f {{ item }}'
with_items:
- "{{ yaml_files.stdout_lines }}"
when: lookup('file', item) is search('kind\:\ Namespace')
It should work for you