skipping does not show for lists

8 views
Skip to first unread message

Jerome Yanga

unread,
Mar 14, 2019, 12:41:56 PM3/14/19
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages