summaryrefslogtreecommitdiffstats
path: root/playbooks/gce/openshift-cluster/tasks/launch_instances.yml
blob: a68edefae90891e3ed1bdbb69da574df7dfeb451 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
---
# TODO: when we are ready to go to ansible 1.9+ support only, we can update to
# the gce task to use the disk_auto_delete parameter to avoid having to delete
# the disk as a separate step on termination
- name: Launch instance(s)
  gce:
    instance_names: "{{ instances }}"
    machine_type: "{{ lookup('env', 'gce_machine_type') | default('n1-standard-1', true) }}"
    image: "{{ lookup('env', 'gce_machine_image') | default(deployment_vars[deployment_type].image, true) }}"
    service_account_email: "{{ lookup('env', 'gce_service_account_email_address') }}"
    pem_file: "{{ lookup('env', 'gce_service_account_pem_file_path') }}"
    project_id: "{{ lookup('env', 'gce_project_id') }}"
    tags:
      - created-by-{{ lookup('env', 'LOGNAME') |default(cluster, true) }}
      - env-{{ cluster }}
      - host-type-{{ type }}
      - env-host-type-{{ cluster }}-openshift-{{ type }}
      - deployment-type-{{ deployment_type }}
  register: gce

- name: Add new instances to groups and set variables needed
  add_host:
    hostname: "{{ item.name }}"
    ansible_ssh_host: "{{ item.public_ip }}"
    ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user | default(ansible_ssh_user, true) }}"
    ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}"
    groups: "{{ item.tags | oo_prepend_strings_in_list('tag_') | join(',') }}"
    gce_public_ip: "{{ item.public_ip }}"
    gce_private_ip: "{{ item.private_ip }}"
  with_items: gce.instance_data

- name: Wait for ssh
  wait_for: port=22 host={{ item.public_ip }}
  with_items: gce.instance_data

- name: Wait for user setup
  command: "ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null {{ hostvars[item.name].ansible_ssh_user }}@{{ item.public_ip }} echo {{ hostvars[item.name].ansible_ssh_user }} user is setup"
  register: result
  until: result.rc == 0
  retries: 20
  delay: 10
  with_items: gce.instance_data