tansudasli.gcp_instances

角色名称

在GCP上提供符合生产级要求的计算实例。

  • 实例
  • 专用引导磁盘
  • 专用数据和日志磁盘
  • 静态IP

要求

  • ansible 客户端
  • ansible.cfg 文件
  • 服务账号和GCP账号

角色变量

该角色默认支持 独立 供给。如果您想要 分布式 供给,可以在您正在运行的yaml文件中提供更多节点,并使用合适的命名约定。

defaults/main.yml,

# GCP项目
general:
    project: sandbox-236618       # GCP项目ID 
    region: europe-west4          # GCP区域
    auth_kind: serviceaccount     
    service_account_file: ~/.ssh/ansible.json
scopes:
    - https://www.googleapis.com/auth/compute

# 设计您的基础架构架构
nodes:
  - name: standalone-node    # 节点名称,例如 standalone-node/name-node/secondary-name-node/data-node1/data-node2 ..
    zone: europe-west4-a     # 选择相近的区域,分布到其他节点
    machine_type: f1-micro   # 需要时增加
    ips:
        - nic: 
            name: "ip-01"
    tags: hadoop             # 防火墙规则使用的网络标签!请使用工具名称,例如 hadoop, elasticsearch ...
    labels:                  # 过滤!使用工具名称加类型 + master/worker 作为名称
        type: hdfs
        name: master
    boot_disk:
        - disk:
            name: "boot-disk-01"
            size: 100
            image: "projects/ubuntu-os-cloud/global/images/family/ubuntu-2004-lts"
            auto_delete: true
            boot: true
    additional_disks:
        - disk: 
            name: "data-disk-01"
            size: 300
            auto_delete: true     # 在生产使用案例中,false 更好
            boot: false
        - disk: 
            name: "log-disk-01"
            size: 300
            auto_delete: true     # 在生产使用案例中,false 更好
            boot: false

依赖

示例剧本

点击这里 来测试和查看示例剧本。

ansible.cfg

[defaults]
host_key_checking = False
inventory = hosts

remote_user = tansudasli                          # 您的 GCP 账户
private_key_file = ~/.ssh/google_compute_engine   # 如果设置,将始终使用此进行身份验证

[inventory]
# 启用的清单插件列表及其使用顺序。
enable_plugins = host_list, script, yaml, ini, auto, gcp_compute

provision.yaml

- name: 创建计算实例
  hosts: localhost
  gather_facts: no

   vars:
     general:
         project: sandbox-236618
         region: europe-west4
         auth_kind: serviceaccount
         service_account_file: ~/.ssh/ansible.json
     scopes:
         - https://www.googleapis.com/auth/compute
          
  tasks:

  roles:
    # 使用默认变量值运行
    - role: tansudasli.gcp_instances  

许可证

Apache-2.0

作者信息

tansudasli

关于项目

Provisions compute instance(s) on GCP with production grade requirements.

安装
ansible-galaxy install tansudasli.gcp_instances
许可证
apache-2.0
下载
85
拥有者
Ansible role boilerplates to inject into the projects that runs on GCP