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 -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/fb4360c2-7422-4e55-a75b-13e2dafc5b0e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
