Here are some background info.
Ansible Version: 2.7.8
Created a file and folder structure with the commands below.
TEMP="/data"
mkdir -p $TEMP/dir{1,2}
touch $TEMP/file{1,2}.txt
touch $TEMP/file{3,4}.lst.txt
touch $TEMP/dir{1,2}/file{1,2}.txt
touch $TEMP/dir{1,2}/file{3,4}.lst.txt
The resulting file and folder structure will be as follows.
# ls -lhR $TEMP
/data:
total 0
drwxr-xr-x 2 root root 82 Mar 14 16:37 dir1
drwxr-xr-x 2 root root 82 Mar 14 16:37 dir2
-rw-r--r-- 1 root root 0 Mar 14 16:37 file1.txt
-rw-r--r-- 1 root root 0 Mar 14 16:37 file2.txt
-rw-r--r-- 1 root root 0 Mar 14 16:37 file3.lst.txt
-rw-r--r-- 1 root root 0 Mar 14 16:37 file4.lst.txt
/data/dir1:
total 0
-rw-r--r-- 1 root root 0 Mar 14 16:37 file1.txt
-rw-r--r-- 1 root root 0 Mar 14 16:37 file2.txt
-rw-r--r-- 1 root root 0 Mar 14 16:37 file3.lst.txt
-rw-r--r-- 1 root root 0 Mar 14 16:37 file4.lst.txt
/data/dir2:
total 0
-rw-r--r-- 1 root root 0 Mar 14 16:37 file1.txt
-rw-r--r-- 1 root root 0 Mar 14 16:37 file2.txt
-rw-r--r-- 1 root root 0 Mar 14 16:37 file3.lst.txt
-rw-r--r-- 1 root root 0 Mar 14 16:37 file4.lst.txt
Here is the contents of the playbook.
---
- name: playbook for testing functionalities
hosts: all
gather_facts: true
become: yes
roles:
- testingPlays
Here is the content of defaults/main.yml
pathToFiles: "/data"
fileGlob: '*.txt'
fileGlobExclude: '*.lst.txt'
Here is the content of tasks/main.yml
---
- name: find certain text files
find:
paths: "{{ pathToFiles }}"
patterns: "{{ fileGlob }}"
excludes: "{{ fileGlobExclude }}"
file_type: file
follow: yes
hidden: yes
recurse: yes
register: textFiles
- name: output textFiles
debug:
msg: "{{ textFiles }}"
when: textFiles.matched > 0
- name: output textFiles.files
debug:
msg: "{{ item.path }}"
with_items: "{{ textFiles.files }}"
when: textFiles.matched > 0
Here is the problem.
When the text files exists, the playbook works just fine.
When the text files are not there, the task "output textFiles.files" does
not say "skipping: [HOSTNAME]"
Help.
Regards,
j
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/951dbaaa-38dd-4baa-93f5-c8bbb3e1d66f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.