我有一组角色需要使用 ansible-galaxy 安装。
- src: 'https://gitlab.private/role-openstack-net.git'
scm: 'git'
version: '1.0.0'
name: 'role-openstack-net'
- src: 'https://gitlab.private/role-openstack-subnet.git'
scm: 'git'
version: '1.0.0'
name: 'role-openstack-subnet'
在实际情况下,我有大约 20 个角色。
所有角色都是私有(private)的,所以当我运行时:
ansible-galaxy install -f -c -r galaxy.yml
它要求我为每个角色提供用户/通行证,这有点麻烦
手动,我这样做:
git config --global credential.helper store
我输入一次我的凭据,然后它会记住所有的
但是在 Jenkins Job 中我应该怎么做呢?
我在这里看到有一种放置 token 的方法:
https://github.com/ansible/ansible/pull/34621
但是好像不行。
有什么想法吗?
最佳答案
目前不支持在运行时将凭证参数传递到 ansible-galaxy。
可以将凭据添加到 requirements.yml
中,但通常将凭据添加到代码中并不理想,因为有朝一日其他人很容易利用它们。
解决方案是在运行时更新requirements.yml
。
通过查看您的个人资料并更新设置来创建 Gitlab 个人访问 token : https://private.gitlab/profile/personal_access_tokens
使用您选择的 secret 管理器在运行时使用 token 设置变量 PAT_TOKEN。
在你的 Jenkins 脚本中使用 sed
在 ansible-galaxy install
之前更新 requirements.yml
sed -i "s#https://gitlab.private/#https://oauth2:${PAT_TOKEN}@gitlab.private/#g" requirements.yml
如果您使用的是 Gitlab-ci 而不是 Jenkins,则可以使用现有的 ci token :
sed -i "s#https://gitlab.private/#https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.private/#g" requirements.yml
关于git - 在 Jenkins 作业中使用 ansible-galaxy 的凭证和私有(private) gitlab 仓库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49737069/