You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ansible...@googlegroups.com
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
Brian Coca
unread,
Dec 19, 2014, 12:15:09 PM12/19/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ansible...@googlegroups.com
look at the failed_when directive, it allows you to chose the failure
condition of a task.
--
Brian Coca
rambius
unread,
Dec 24, 2014, 12:57:47 PM12/24/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ansible...@googlegroups.com
Hello,
19 декември 2014, петък, 12:15:09 UTC-5, Brian Coca написа:
look at the failed_when directive, it allows you to chose the failure
condition of a task.
Thank you. failed_when did the job. My playbook now looks like
---
- name: ensure server is not running command: pgrep -f programname register: is_server_running