[英]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.