小编Cha*_*ard的帖子

我可以在ansible-galaxy和requirements.yml中使用变量替换吗?

我们为许多Ansible角色提供了私人git仓库。回购主机因站点而异,例如:

  • Site1的用途 https://gitforsite1.ourdomain.com
  • Site2的用途 https://gitforsite2.ourdomain.com

我想要的是只有一个requirements.yml文件,并替换正确的git repo。我可以这样做的一种方法是让bash脚本设置环境变量:

#!/bin/bash
...
if [ "$1" = "site1" ]; then
    export REPO_ROOT="https://gitforsite1.ourdomain.com"
fi
if [ "$1" = "site2" ]; then
    export REPO_ROOT="https://gitforsite2.ourdomain.com"
fi
... error checking if the value is not site1 or site2 ...
# Then install the roles
ansible-galaxy install -f -r config/requirements.yml -p roles
Run Code Online (Sandbox Code Playgroud)

然后将该值替换为requirements.yml

---

- src: {{ lookup('env', 'REPO_ROOT') }}/role1.git
  name: role1

- src: {{ lookup('env', 'REPO_ROOT') }}/role.git
  name: role2
Run Code Online (Sandbox Code Playgroud)

这种方法给出:ERROR! Unable to load …

bash yaml substitution ansible

5
推荐指数
1
解决办法
1191
查看次数

标签 统计

ansible ×1

bash ×1

substitution ×1

yaml ×1