我们为许多Ansible角色提供了私人git仓库。回购主机因站点而异,例如:
https://gitforsite1.ourdomain.com 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 …