jasonheecs.digitalocean
Ansible 角色:数字海洋 Droplet 创建
一个 Ansible 角色,用于创建数字海洋的 Droplet,并将 Droplet 的 IP 地址添加到清单文件中。
要求
无。
安装
ansible-galaxy install jasonheecs.digitalocean
角色变量
角色变量列在 defaults/main.yml
中,敏感变量(如您的数字海洋 API 令牌)应列在 vars/private.yml
中。
可用变量如下,包含默认值(请参见 defaults/main.yml
和 vars/private.yml.example
):
# 您在数字海洋账户中的 SSH 密钥标识
do_ssh_key_name: Ansible SSH Key
# 要添加到您帐户的公有 SSH 密钥
do_ssh_pub_key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
# 用于通过 SSH 连接到 Droplet 的私钥
do_ssh_private_key: "~/.ssh/id_rsa"
# Droplet 的名称
droplet_name: test-droplet
# 要创建服务器的地区标识
droplet_region_id: sgp1
# 希望创建的 Droplet 的大小标识
droplet_size_id: 512mb
# 希望创建的 Droplet 的镜像标识
droplet_image_id: ubuntu-18-04-x64
# Ansible 清单文件的位置
ansible_inventory_file: hosts.ini
# 用于在清单文件中分组 Droplet 的组名称
droplets_inventory_group: do_droplets
# 您的数字海洋个人访问令牌 (https://www.digitalocean.com/community/tutorials/how-to-use-the-digitalocean-api-v2)
do_api_token: inserttokenhere
# 在创建过程中要添加到 Droplet 的其他 SSH 密钥 (https://developers.digitalocean.com/documentation/v2/#ssh-keys)
droplet_additional_ssh_key_ids: []
依赖关系
无。
示例剧本
在远程机器上运行此角色的剧本:
- hosts: all
become: no
roles:
- { role: jasonheecs.digitalocean }
在本地机器上运行此角色的剧本:
- hosts: localhost
connection: local
become: no
roles:
- { role: jasonheecs.digitalocean }
请参阅 此处的示例剧本。
测试
自动化测试通过 Test Kitchen,Kitchen Ansible 和 Kitchen Docker 完成。
要运行测试,请确保已安装 Ruby 和 Docker,然后运行以下命令:
gem install bundler && bundle exec kitchen test
有关测试构建过程和预期输出的详细信息,请参阅 travis.yml 文件和 Travis 构建日志。
支持的平台
此 Ansible 角色已在以下平台上测试:
- macOS Sierra
- macOS High Sierra
- Ubuntu 16.04
- Ubuntu 14.04
- CentOS 7
- Debian 9
许可证
MIT