From 065749ee2aaed1a9f693b320ae1984088b7c45ae Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Wed, 12 Oct 2016 17:36:40 -0400 Subject: [PATCH] Change example syntax on stat module --- lib/ansible/modules/files/stat.py | 39 ++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/lib/ansible/modules/files/stat.py b/lib/ansible/modules/files/stat.py index 7f522abb0ca..363e94ad3f7 100644 --- a/lib/ansible/modules/files/stat.py +++ b/lib/ansible/modules/files/stat.py @@ -77,9 +77,11 @@ author: "Bruce Pennypacker (@bpennypacker)" EXAMPLES = ''' # Obtain the stats of /etc/foo.conf, and check that the file still belongs # to 'root'. Fail otherwise. -- stat: path=/etc/foo.conf +- stat: + path: /etc/foo.conf register: st -- fail: msg="Whoops! file ownership has changed" +- 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 @@ -87,30 +89,45 @@ EXAMPLES = ''' # 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 +- stat: + path: /path/to/something register: sym -- debug: msg="islnk isn't defined (path doesn't exist)" + +- 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)" + +- debug: + msg: "islnk is defined (path must exist)" when: sym.stat.islnk is defined -- debug: msg="Path exists and is a symlink" + +- 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" + +- 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 +- stat: + path: /path/to/something register: p -- debug: msg="Path exists and is a directory" +- debug: + msg: "Path exists and is a directory" when: p.stat.isdir is defined and p.stat.isdir # Don't do md5 checksum -- stat: path=/path/to/myhugefile get_md5=no +- stat: + path: /path/to/myhugefile + get_md5: no # Use sha256 to calculate checksum -- stat: path=/path/to/something checksum_algorithm=sha256 +- stat: + path: /path/to/something + checksum_algorithm: sha256 ''' RETURN = '''