0
votes

I'm creating instance in Google Cloud with Ansible, but when I want to attach existing disk to new compute engine, I can't attach it or add it to instance.

- name: Launch instances
  gce:
    instance_names: mongo
    machine_type: "n1-standard-1"
    image: "debian-9"
    service_account_email: "[email protected]"
    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 }}"

The error I have is:

The error was: libcloud.common.google.ResourceExistsError: {'domain': 'global', 'message': "The resource 'projects/xxx-xxx/zones/us-central1-a/disks/mongo' already exists", 'reason': 'alreadyExists'}

There are any form to configure this option with Ansible? To do that now I'm using external scripts.

1

1 Answers

1
votes

Existing disks can be provided as a list under 'disks' attribute, first entry needs to be 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