cancel
Showing results for 
Search instead for 
Did you mean: 
harjitsachar
Flight Engineer
Flight Engineer
  • 323 Views

Clarity required for small Ansible code segment

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 

when:  lock.stat.exists

rather than what is written.

Labels (1)
0 Kudos
1 Reply
andkra
Flight Engineer Flight Engineer
Flight Engineer
  • 309 Views

Re: Clarity required for small Ansible code segment

Hello,

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
  debug:
    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.

0 Kudos
Reply
Loading...
Join the discussion
You must log in to join this conversation.