Created
June 5, 2014 14:58
-
-
Save halberom/7ba0b251a45291621be4 to your computer and use it in GitHub Desktop.
ansible - example of doing something if a file exists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the file doesn't exist | |
TASK: [debug var=foo] ********************************************************* | |
ok: [localhost] => { | |
"foo": { | |
"changed": false, | |
"invocation": { | |
"module_args": "path=/tmp/file", | |
"module_name": "stat" | |
}, | |
"stat": { | |
"exists": false | |
} | |
} | |
} | |
TASK: [do something with file if exists] ************************************** | |
skipping: [localhost] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
vars: | |
mypath: /tmp/file | |
tasks: | |
- stat: path={{mypath}} | |
register: foo | |
- debug: var=foo | |
- name: do something with file if exists | |
command: cat {{ mypath }} | |
when: foo.stat.exists |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment