[STAT] Execute script if it's exist

19 views
Skip to first unread message

COUSSI Matthieu

unread,
Dec 24, 2018, 8:46:45 AM12/24/18
to Ansible Project
Hi,

I want to execute a command if a file exist.

The script juste create a file in the same folder.
 #/bin/sh


 touch test
.txt



Ansible execute module below.
 ---
 
# Vérification
 
- name: Vérification si le script existe
   stat
:
 path
: "/tmp/test.sh"
   
register: file_exist


 
# Exécution
 
- name: Exécution du script si il existe
   shell
: "/tmp/test.sh"
   
when: file_exist.stat.exists

...

This is the result on screen
 TASK [LINUX_test : Vérification si le script existe] *********************************************************************************************
 ok
: [test1]


 TASK
[LINUX_test : Exécution du script si il existe] *********************************************************************************************
 changed
: [test1]



But the script doesn't create the file in the same folder.

Do you have an idea?

Thanks for your help,

Matt

COUSSI Matthieu

unread,
Dec 24, 2018, 9:13:10 AM12/24/18
to Ansible Project
In fact, the file is created in /rppt.

It's ok :)

Matt
Reply all
Reply to author
Forward
0 new messages