如何成功退出剧本任务

时间:2019-05-03 04:56:39

标签: ansible ansible-2.x

我有一个剧本正在重复一个任务,从ansible任务调用了shell,但是在完成任务并再次重复shell指令后,它并没有成功退出。

剧本:

---
hosts: dev-servers

tasks:

  - name: clean up directoty
    shell: rm -rf /opt/data/latest/*

  - name: copy the file
    copy: src=/home/data/metadata.zip dest=/opt/data

  - name: Change directoty
    shell: cd /opt/data

  - name: copy the file
    copy: src=/root/Run_Build.sh dest=/opt/deployment_scripts

  - name: permission
    shell: chmod +x /opt/deployment_scripts/Run_Build.sh

  - name: deploy
    command: sh /opt/deployment_scripts/Run_Build.sh
    run_once: true
    register: result

  - debug: msg="{{ result.stdout }}"

  - debug: msg="{{ result.stderr }}"

Run_Build.sh:

#!/bin/bash

Jboss_logs=/opt/jboss/jboss-eap-6.4/standalone/log/server.log

for i in {1..100}; do
    sleep 10
    if [ -f  $Jboss_logs/server.log ]; then
        if  grep -e 'Deployed "deploy.war"' $Jboss_logs/server.log ; then

            echo "Code successfully deployed"
            exit 0

        else
            echo "*****************************************************************************"
            echo " JBOSS is still loading deployment - please be patient .... Loading again in 10 sec" 
            echo "*****************************************************************************" 
        fi
    else
        echo "server log file has not been created yet, please wait for sometime."
    fi
done

0 个答案:

没有答案