【问题标题】:Attach boot disk if exist to Gcloud instance with Ansible使用 Ansible 将启动磁盘(如果存在)附加到 Gcloud 实例
【发布时间】:2019-02-25 22:31:02
【问题描述】:

我正在使用 Ansible 在 Google Cloud 中创建实例,但是当我想将现有磁盘附加到新的计算引擎时,我无法附加它或将其添加到实例。

- name: Launch instances
  gce:
    instance_names: mongo
    machine_type: "n1-standard-1"
    image: "debian-9"
    service_account_email: "xxxx@xxxx.iam.gserviceaccount.com"
    credentials_file: "gcp-credentials.json"
    project_id: "learning"
    disk_size: 10
    disk_auto_delete: false
    preemptible: true
    tags: "mongo-server"
  register: gce

- name: Wait for SSH for instances 
  wait_for:
    delay: 1
    host: "{{ item.public_ip }}"
    port: 22
    state: started
    timeout: 30
  with_items: "{{ gce.instance_data }}"

我的错误是:

错误是:libcloud.common.google.ResourceExistsError: {'domain': 'global', 'message': "The resource 'projects/xxx-xxx/zones/us-central1-a/disks/mongo'已经存在", '原因': 'alreadyExists'}

有任何形式可以用 Ansible 配置这个选项吗?为此,我现在使用外部脚本。

【问题讨论】:

    标签: ansible gcloud


    【解决方案1】:

    现有磁盘可以在'disks'属性下作为列表提供,第一个条目需要是Boot dik

    https://docs.ansible.com/ansible/2.6/modules/gce_module.html

      - gce:
      instance_names: my-test-instance
      zone: us-central1-a
      machine_type: n1-standard-1
      state: present
      metadata: '{"db":"postgres", "group":"qa", "id":500}'
      tags:
        - http-server
        - my-other-tag
      disks:
        - name: disk-2
          mode: READ_WRITE
        - name: disk-3
          mode: READ_ONLY
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      • 2014-12-01
      相关资源
      最近更新 更多