ANSIBLE编写的应用系统一键关停启动脚本

关停脚本:

---
- hosts: IP地址
  remote_user: username
  tasks:
    - name: stop app1
      shell: "ps -ef|grep app1|grep -v grep|awk '{print $2}'|xargs -r kill"
      register: startup_out
      
    - name: print stop app1
      debug: var=startup_out
      

- hosts: IP地址
  remote_user: username
  tasks:
    - name: stop app2
      shell: "ps -ef|grep app2|grep -v grep|awk '{print $2}'|xargs -r kill"
      register: startup_out
      
    - name: print stop app2
      debug: var=startup_out
      
    - name: sleep 60s
      slell: "sleep 60"

启动脚本和关停是一样的,只是命令换了

---
- hosts: IP地址
  remote_user: username
  tasks:
    - name: start app1
      shell: "source /etc/profile; nohup /tomcat/bin/startup.sh &"
      register: startup_out
      ignore_errors: yes
    - name: print start app1
      debug: var=startup_out
      ignore_errors: yes

      
- hosts: IP地址
  remote_user: username
  tasks:
    - name: start app2
      shell: "source /etc/profile; nohup /tomcat/bin/startup.sh &"
      register: startup_out
      ignore_errors: yes
    - name: print start app2
      debug: var=startup_out
      ignore_errors: yes

注意,hosts当中指向的IP地址必须在/etc/ansible/hosts里面有,remote_user当然也需要做过ssh认证,否则剧本都跑不起来

猜你喜欢

转载自blog.csdn.net/lsysafe/article/details/85014078