Hello,
I am new to ansible and I am experimenting with a simple playbook I created. My question is how to negate the return code of a command. I use pgrep to check if a server is running and if it is not running I will back it up. If it is running the playbook should fail with an appropriate message. I use the following snippet that works:
- name: ensure server is not running
command: pgrep -f programname
register: is_server_running
ignore_errors: True - name: backup server
when: is_server_running|failed
command: serverbackup.sh
This looks clumsy though. I tried with the following but does not work:
- name: ensure server is not running
command: ! pgrep -f programname
! pgrep -f programname works fine when I execute it directly from the command line.
I would be very grateful for any help.
Regards
Rambius