tasks: - name: Check if /var/run/app.lock exists stat: path: /var/run/app.lock register: lock - name: Fail if the application is running fail: when: not lock.stat.exists
Can you validate if the excerpt of code is doing opposite of what it should. The when clause should be
rather than what is written.
Code is OK.
fail failed when when is True ;-)
lock.stat.exists is False if file does not exists.
you can verify if you look what the content of lock is.
- name: print var lock
Pay attention. I think there was a change in one of the previous ansible versions with the stat module. Means, it could depend on the ansible version.