Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible stop playbook if file present

Is it possible to stop a playbook during his execution if a define file is present on my node and also output to explain why the playbook has stopped?

It is to prevent an accidental re-execution of my playbook on a node that has my application already installed because I generate a password during this install and I don't want to reinitialise this password.

like image 399
vlaneo Avatar asked May 20 '16 13:05

vlaneo


1 Answers

You can use the fail module to force a failure with a custom failure message.

Couple this with a check for a file, using the stat module, and this should work easily enough for you.

A quick example or a one run playbook might look something like this:

- name: check for foo.conf
  stat: path=/etc/foo.conf
  register: foo

- name: fail if already run on host
  fail: msg="This host has already had this playbook run against it"
  when: foo.stat.exists

- name: create foo.conf
  file: path=/etc/foo.conf state=touch
like image 187
ydaetskcoR Avatar answered Nov 06 '22 04:11

ydaetskcoR