如何自动安装Ansible Galaxy角色? [英] How to automatically install Ansible Galaxy roles?
问题描述
我所有的Ansible剧本/角色都签入了我的git repo.
All my Ansible playbooks/roles are checked in to my git repo.
但是,对于Ansible Galaxy角色,我总是必须在要从其运行Ansible的每台计算机上逐个明确地下载它们.
However, for Ansible Galaxy roles I always have to explicitly download them one by one on every machine I want to run Ansible from.
在Ansible抱怨运行时缺少角色之前,甚至很难事先确切地知道需要哪些Ansible Galaxy角色.
It's even tough to know in advance exactly which Ansible Galaxy roles are needed until Ansible complains about a missing role at runtime.
应该如何管理Ansible Galaxy角色依赖性?我想让它们与我的其他Ansible代码一起检入git仓库,或者在我在新计算机上运行Ansible时自动识别并下载它们.
How is one supposed to manage the Ansible Galaxy role dependencies? I would like to either have them checked into my git repo along with the rest of my ansible code or have them automatically be identified and downloaded when I run Ansible on a new machine.
推荐答案
在此用例中,应使用requirements.yml
文件.使用多种安装方法来描述所需的角色:
You should use a requirements.yml
file for this use-case. Describe the roles you require, using any of a variety of install methods:
# Install a role from the Ansible Galaxy
- src: dfarrell07.opendaylight
# Install a role from GitHub
- name: opendaylight
src: https://github.com/dfarrell07/ansible-opendaylight
# Install a role from a specific git branch
- name: opendaylight
src: https://github.com/dfarrell07/ansible-opendaylight
version: origin/master
# Install a role at a specific tag from GitHub
- name: opendaylight
src: https://github.com/dfarrell07/ansible-opendaylight
version: 1.0.0
# Install a role at a specific commit from GitHub
- name: opendaylight
src: https://github.com/dfarrell07/ansible-opendaylight
version: <commit hash>
然后安装它们:
ansible-galaxy install -r requirements.yml
这是一个工作示例(使用Ansible作为Vagrant供应商来安装OpenDaylight).有关更多信息,请参见相关的Ansible文档.
Here's a working example (installing OpenDaylight using Ansible as a Vagrant provisioner). See the relevant Ansible docs for more info.
这篇关于如何自动安装Ansible Galaxy角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!