Ansible: running command only if the file doesn’t exist

In order to achieve this, you have to use Ansible module, ‘command’ . You also have to make sure that the file that you want to execute is already in the remote host.

Command module has ‘creates’ parameter that checks if the folder already been created, if it doesn’t it will run this command, otherwise Ansible will skip this command.

 
- name: Install Intel Compilers (Skip if it's already been installed) 
  command: /tmp/install_compilers.sh creates=/opt/intel 

2 thoughts on “Ansible: running command only if the file doesn’t exist

Leave a Reply

Your email address will not be published. Required fields are marked *