如何自动安装 Ansible Galaxy 角色? [英] How to automatically install Ansible Galaxy roles?
问题描述
我所有的 Ansible 剧本/角色都已签入我的 git 存储库.
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 repo,或者在我在新机器上运行 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屋!