--- - hosts: test gather_facts: F #开启debug vars: war: "ps -ef | grep tomcat | grep -v grep | awk '{print $2}'" tasks: - name: stop tomcat shell: nohup /bin/bash /tmp/stop_tomcat.sh& ignore_errors: True register: tomcat_out #定义变量存储返回的结果 - name: show 结果 #定义输出结果的task debug: var=tomcat_out verbosity=0 #debug的模块显示输出的记过 - name: back war shell: cp /home/admin/taobao-tomcat-production-7.0.59.3/deploy/ROOT.war /tmp/ - name: remove romate dir file: path=/home/admin/taobao-tomcat-production-7.0.59.3/deploy/ROOT state=absent - name: remove romate war file: path=/home/admin/taobao-tomcat-production-7.0.59.3/deploy/ROOT.war state=absent - name: copy war copy: src=/home/admin/.jenkins/jobs/NET-hangfa/workspace/aecc_purchase_portal_web/xx.war dest=/home/admin/taobao-tomcat-production-7.0.59.3/deploy/ROOT.war owner=admin group=wheel mode=0644 - name: start tomcat shell: nohup sh /home/admin/taobao-tomcat-production-7.0.59.3/bin/startup.sh & - name: tomcatalive shell: "{{war}}" register: check - name: show debug: var=check.stdout verbosity=0 #check.stdout 显示出的信息会看的更清晰点