mesaguy.hashicorp
Ansible HashiCorp
使用官方软件包、官方压缩文件和发行版包安装 HashiCorp 软件。
安装和更新以下 HashiCorp 软件:
- Boundary
- Consul
- Consul Template
- EnvConsul
- Nomad
- Packer
- Sentinel
- Serf
- Terraform
- Vagrant
- Vault
- Vault SSH Helper
- Waypoint
该角色可能最终管理一些 HashiCorp 软件,但目前重点是以安全、一致和可重复的方式安装 HashiCorp 软件。
需求
- Ansible >= 2.9.0
- 必须收集事实 (gather_facts: true)
角色变量
通用
默认情况下,该角色不安装任何软件。每个软件必须单独启用。
可以定义以下变量以安装特定的 HashiCorp 软件:
hashicorp_install_boundary: true
hashicorp_install_consul: true
hashicorp_install_consul_template: true
hashicorp_install_envconsul: true
hashicorp_install_nomad: true
hashicorp_install_packer: true
hashicorp_install_sentinel: true
hashicorp_install_serf: true
hashicorp_install_terraform: true
hashicorp_install_vagrant: true
hashicorp_install_vault: true
hashicorp_install_vault_ssh_helper: true
hashicorp_install_waypoint: true
或者,在调用此角色时,可以使用 "hashicorp_install" 变量指定 HashiCorp 软件。当指定 "hashicorp_install" 时,上述 hashicorp_install_* 变量将被忽略。此语法还支持可选指定版本:
- name: 包含 mesaguy.hashicorp 以安装特定软件
include_role:
name: mesaguy.hashicorp
vars:
hashicorp_install:
# 安装 Consul 版本 1.0.0
- consul==1.0.0
# 安装最新版本的 packer 和 vault
- packer
- vault
HashiCorp ZIP 文件安装
默认情况下,该角色使用以下变量安装包含预编译二进制文件的 HashiCorp ZIP 文件。
软件安装到这个基础目录。例如,consul 版本 1.0.0 的二进制文件将安装到 /opt/hashicorp/consul/1.0.0/consul。
hashicorp_base_dir: /opt/hashicorp
在这里创建每个二进制文件的符号链接:
hashicorp_software_link_dir: /usr/local/bin
验证所有发布 ZIP 文件的 GPG 签名(默认:false)。这要求 "gpg" 命令可用。如果缺少 HashiCorp GPG 发布公钥,则该角色会自动将 GPG 公钥添加到 "root" 用户的 GPG 密钥环中:
hashicorp_check_gpg_signatures: true
清除除最新软件版本之外的所有版本(默认:false):
hashicorp_purge_old_releases: true
更改拥有软件的用户,默认选项如下:
hashicorp_user: root
hashicorp_group: root
如果有 HashiCorp 软件的本地镜像,可以使用 "HASHICORP_MIRROR" 和/或 "HASHICORP_GPG_MIRROR" 环境变量或以下 ansible 变量。 "hashicorp_gpg_mirror" 变量仅影响 GPG 签名文件的来源:
hashicorp_mirror: https://example.org/hashicorp
hashicorp_gpg_mirror: https://example.org/hashicorp
使用 HashiCorp 软件包而不是 ZIP 文件
启用时,使用 HashiCorp 的官方 RPM/DEB 软件包而不是 HashiCorp 的官方 ZIP 文件,默认值为 false:
hashicorp_use_official_packages: true
此选项适用于以下发行版和架构:
发行版 | 版本 | 架构 |
---|---|---|
AmazonLinux | 2 | amd64/x86_64 |
Debian | Jessie (8) | amd64/x86_64 |
Debian | Stretch (9) | amd64/x86_64 |
Debian | Buster (10) | amd64/x86_64 |
Fedora | 29 | amd64/x86_64 |
Fedora | 30 | amd64/x86_64 |
Fedora | 31 | amd64/x86_64 |
Fedora | 32 | amd64/x86_64 |
Fedora | 33 | amd64/x86_64 |
RHEL | 7 | amd64/x86_64 |
RHEL | 8 | amd64/x86_64 |
Ubuntu | Bionic (18.04) | amd64/x86_64 |
Ubuntu | Eoam (19.10) | amd64/x86_64 |
Ubuntu | Focal (20.04) | amd64/x86_64 |
Ubuntu | Groovy (20.10) | amd64/x86_64 |
Ubuntu | Xenial (16.04) | amd64/x86_64 |
清除通过 ZIP 文件安装的 HashiCorp 软件,默认值为 false:
hashicorp_purge_zip_releases: true
可以使用 "hashicorp_apt_mirror" ansible 变量或 "HASHICORP_APT_MIRROR" 环境变量指定本地 apt 镜像:
hashicorp_apt_mirror: https://example.org/hashicorp/apt
可以使用 "hashicorp_yum_mirror" ansible 变量或 "HASHICORP_YUM_MIRROR" 环境变量指定本地 yum 镜像:
hashicorp_yum_mirror: https://example.org/hashicorp/yum
保持 HashiCorp 软件的状态,默认值为 "present":
hashicorp_software_state: latest
当安装 HashiCorp 的二进制 ZIP 文件时,使用以下语法指定软件版本:
hashicorp_nomad_version: 1.0.1
hashicorp_vault_version: 1.0.1
使用发行版包而不是 ZIP 文件
启用时,使用发行版的(可能是非官方的)包而不是 HashiCorp 的官方 ZIP 文件,默认值为 false:
hashicorp_use_distro_packages: true
目前,此选项仅适用于 ArchLinux。
清除通过 ZIP 文件安装的 HashiCorp 软件,默认值为 false:
hashicorp_purge_zip_releases: true
可以通过以下方式启用 yum 测试仓库:
hashicorp_enable_yum_test_repo: true
依赖关系
无
示例剧本
以下示例将安装 'Consul' 和 'Vault' 软件:
- hosts: servers
vars:
hashicorp_install_consul: true
hashicorp_install_vault: true
roles:
- { role: mesaguy.hashicorp }
发布管理
更新默认软件版本
默认软件发布版本由 'vars/versions.yml' 和 'docker_versions.yml' 文件控制。
可以手动更新这些文件或通过运行 scripts/update_versions
脚本进行更新。
测试
通过消息分子进行测试。
您需要安装 pipenv 并运行 docker 来进行测试。
在此仓库的基础目录中运行以下命令初始化 pipenv 环境:
pipenv install
可以使用以下命令进行基本验证。第一个测试正常安装,第二个场景确保 GPG 验证工作:
IMAGE_DISTRO=debian IMAGE_TAG=debian-10 pipenv run molecule test
IMAGE_DISTRO=debian IMAGE_TAG=debian-10 pipenv run molecule test -s gpg
Selinux 错误通常可以通过以下方式解决:
pipenv run pip uninstall selinux -y; pipenv install
许可证
MIT
请参阅 LICENSE 文件
作者信息
Mesaguy