I'm am trying to write an ansible script that will generate thread dumps on 
java processes.  Here is my playbook:

---

 - name: generate thread dumps
   hosts: localhost
   user: oracle
   serial: 100%
   vars:
     pid: 0
     serverNames:
         - AdminServer

   tasks:
     - command: "kill -3 `pgrep -f {item}`"
       with_items: serverNames



This is the ansible result:

$ ansible-playbook thread-dump.yml -i inventory -v

PLAY [generate thread dumps] 
**************************************************

GATHERING FACTS 
***************************************************************
ok: [localhost]

TASK: [command kill -3 `pgrep -f {item}`] 
*************************************
failed: [localhost] => (item=AdminServer) => {"changed": true, "cmd": 
["kill", "-3", "`pgrep", "-f", "{item}`"], "delta": "0:00:00.005389", 
"end": "2015-07-09 17:11:38.275632", "item": "AdminServer", "rc": 3, 
"start": "2015-07-09 17:11:38.270243", "warnings": []}
stderr: kill: can't find process "`pgrep"
kill: can't find process "-f"
kill: can't find process "{item}`"

FATAL: all hosts have already failed -- aborting

PLAY RECAP 
********************************************************************
           to retry, use: --limit @/home/oracle/thread-dump.retry

localhost                  : ok=1    changed=0    unreachable=0    failed=1



The command works fine when I run it at the command prompt. 

I have also tried creating a script and executing it with the script 
command.  Here is the kill3.sh script:

kill -3 `pgrep -f $1`

Which also fails:

]$ ansible-playbook thread-dump.yml -i inventory -v

PLAY [generate thread dumps] 
**************************************************

GATHERING FACTS 
***************************************************************
ok: [localhost]

TASK: [script kill3.sh {item}] 
************************************************
failed: [localhost] => (item=AdminServer) => {"changed": true, "item": 
"AdminServer", "rc": 1}
stderr: OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /home/oracle/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: auto-mux: Trying existing master
debug1: mux_client_request_session: master session id: 2
debug1: mux_client_request_session: master session id: 2
Shared connection to localhost closed.

stdout: Invalid preceding regular expressionkill: usage: kill [-s sigspec | 
-n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]


FATAL: all hosts have already failed -- aborting

PLAY RECAP 
********************************************************************
           to retry, use: --limit @/home/oracle/thread-dump.retry

localhost                  : ok=1    changed=0    unreachable=0    failed=1


Note the script works fine when I run it from the command prompt. 

What am I doing wrong?

Thanks in advance for any assistance. 

Jane




-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a045f3db-9b44-41f9-92b3-c1f2e90af6b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to