ansible 啓動tomcat/中止tomcat

用service模塊寫的playbook執行完了,目標機器的tomcat狀態沒變,這個但願大神指導一下!!!web

下面是用shell模塊寫的playbook內容。
啓動tomcatshell

--- - hosts: vm   remote_user: root
  tasks:
  - name: 啓動tomcat     shell: nohup /opt/dev/tomcat7/apache-tomcat-7.0.65/bin/startup.sh &

若是有報錯說權限不夠,就給startup.sh的執行權限apache

chmod u+x /opt/dev/tomcat7/apache-tomcat-7.0.65/bin/startup.sh

中止tomcattomcat

---
- hosts: vm 
  remote_user: root
  tasks:
  - name: 中止tomcat
    shell: ps -fe | grep "/opt/dev/tomcat7/apache-tomcat-7.0.65" | grep -v grep | tr -s " "|cut -d" " -f2 | xargs kill -9

tomcat的路徑要改爲你實際的絕對路徑。ruby