From b664603a4d7739928ef9c45c56f90d9cbb77b8d0 Mon Sep 17 00:00:00 2001 From: Mitchell Ludwig Date: Mon, 13 Jul 2015 17:51:32 -0600 Subject: [PATCH] Improved stat documentation --- lib/ansible/modules/files/stat.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/ansible/modules/files/stat.py b/lib/ansible/modules/files/stat.py index 5f79874d9fd..2e088fc8dbd 100644 --- a/lib/ansible/modules/files/stat.py +++ b/lib/ansible/modules/files/stat.py @@ -58,6 +58,23 @@ EXAMPLES = ''' - fail: msg="Whoops! file ownership has changed" when: st.stat.pw_name != 'root' +# Determine if a path exists and is a symlink. Note that if the path does +# not exist, and we test sym.stat.islnk, it will fail with an error. So +# therefore, we must test whether it is defined. +# Run this to understand the structure, the skipped ones do not pass the +# check performed by 'when' +- stat: path=/path/to/something + register: sym +- debug: msg="islnk isn't defined (path doesn't exist)" + when: sym.stat.islnk is not defined +- debug: msg="islnk is defined (path must exist)" + when: sym.stat.islnk is defined +- debug: msg="Path exists and is a symlink" + when: sym.stat.islnk is defined and sym.stat.islnk +- debug: msg="Path exists and isn't a symlink" + when: sym.stat.islnk is defined and sym.stat.islnk == False + + # Determine if a path exists and is a directory. Note that we need to test # both that p.stat.isdir actually exists, and also that it's set to true. - stat: path=/path/to/something