bash - 如何使用 ansible playbook 将变量放入 bash 脚本中
问题描述
我需要一个带有 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
这是我的 ansible 剧本:
- 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 }}'
推荐阅读
- encryption - javacardx AES 加密不等于 javax AES 解密
- mysql - Oracle 中是否有与 WITH 关键字等效的 MySQL
- firebase - Firestore 定价 - 实时更新侦听器计为一次读取或数据更改次数
- markdown - 降价中是否可以有非标题锚?
- python - python中treeview中使用bbox的示例
- angular - ngOnInit() 中的 router.navigate 在页面重新加载时不起作用
- python - 使用moviepy连接电影剪辑的更快方法?
- wordpress - 向 Woocommerce 用户我的帐户页面添加高级自定义字段
- angular - 如何在 Typescript 的泛型方法中获取 T 的类型?
- webpack - 使用 Webpack 处理 SCSS 中的图像