簡體   English   中英

如何使用Ansible Playbook將變量放入Bash腳本

[英]How to put variable in bash script with ansible playbook

我需要Ansible劇本在腳本中放置一個put變量。 我從Jenkins'build with parameter'中獲取了變量,但是我無法在腳本中放置“ tag”變量。 我怎樣才能做到這一點?

這是我的腳本:

export JAVA_HOME=/home/asd/products/app/java8

tag=$(tag)

hzpid=$(ps aux  |grep /home/asd/products/app/hzcluster/ |grep -v grep |  awk '{print $2}' | sed -r 's/%/ /g')

echo $hzpid

if [[ -z $hzpid ]]; then

echo "no running applications"

else

kill -9 $hzpid &&  echo "running process terminated."

fi


nohup $JAVA_HOME/bin/java -Dspring.profiles.active=dxl-dev -jar /home/asd/products/app/hzcluster/new/hzcluster-$tag-SNAPSHOT.jar > $LOG_DIR/hzcluster.log &

exit 0 

這是我的老戲:

- hosts: '{{ hosts }}'
  gather_facts: no
  tasks:
    - name: Run new hzcluster.jar
      shell: sh  '{{ sh_file }}'start-hzcluster2.sh '{{ tag }}'

在您的Shell腳本中,從tag=$(tag)更改為tag=$1

劇本:

- hosts: '{{ hosts }}'
  gather_facts: no
  tasks:
    - name: Run new hzcluster.jar
      shell: sh  '{{ sh_file }}'start-hzcluster2.sh '{{ tag }}'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM