Bootstrap

ansible中 yaml 判断返回值

ansible中 yaml 判断返回值 

ps -ef|grep -v grep|grep java1 > /dev/null && echo "running"||echo "stopped"

ansible-playbook -v -i /data/ld_fabu/ansible_cfg/hosts /data/ld_fabu/env_online/ansible_yaml/svn/ldgame_StopStatic.yaml --extra-vars "EnvValue=env_online DstSvr=static1"

-v 显示详细结果

停止进程

---

- hosts: "{{DstSvr}}"

remote_user: ledou00

tasks:

- name: jude java process is exsit

shell: ps -ef|grep -v grep|grep java >/dev/null && echo "running" || echo "stopped"

ignore_errors: True

register: result1

- name: stop java process

shell: ps -ef|grep -v grep|grep java|awk '{print $2}'|xargs kill

when: result1.stdout=='running'

启动进程判断

---

- hosts: "{{DstSvr}}"

#- hosts: logicplayer

remote_user: ledou00

tasks:

- name: jude java process is exsit port 8083

shell: ps -ef|grep -v grep|grep "port=8083" >/dev/null && echo "running"||echo "stopped"

ignore_errors: True

register: java_status

- name: jude hostname match Q-hk-aoa-static1 or Q-hk-aoa-static2

shell: hostname|grep -w "Q-hk-aoa-static[1-2]" >/dev/null && echo "static_svr"||echo "no_static_svr"

ignore_errors: True

register: host_value

when: java_status.stdout=='stopped'

- name: start java process

shell: cd /data/game/aoa/web/static_web_8083;/bin/bash start.sh

ignore_errors: True

# register: host_value

when: java_status.stdout=='stopped' and host_value.stdout=='static_svr'

;