summaryrefslogtreecommitdiffstats
path: root/playbooks/aws/openshift-cluster/launch_instances.yml
blob: e4d5952fd3bd094a6267fe59bb317e85f2f84ea3 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
- set_fact:
    machine_type: "{{ lookup('env', 'ec2_instance_type')|default('m3.large', true) }}"
    machine_image: "{{ lookup('env', 'ec2_ami')|default('ami-307b3658', true) }}"
    machine_region: "{{ lookup('env', 'ec2_region')|default('us-east-1', true) }}"
    machine_keypair: "{{ lookup('env', 'ec2_keypair')|default('libra', true) }}"
    created_by: "{{ lookup('env', 'LOGNAME')|default(cluster, true) }}"
    env: "{{ cluster }}"
    host_type: "{{ type }}"
    env_host_type: "{{ cluster }}-openshift-{{ type }}"

- name: Launch instance(s)
  ec2:
    state: present
    region: "{{ machine_region }}"
    keypair: "{{ machine_keypair }}"
    group: ['public']
    instance_type: "{{ machine_type }}"
    image: "{{ machine_image }}"
    count: "{{ instances | oo_len }}"
    wait: yes
    instance_tags:
      created-by: "{{ created_by }}"
      env: "{{ env }}"
      host-type: "{{ host_type }}"
      env-host-type: "{{ env_host_type }}"
  register: ec2

- name: Add Name tag to instances
  ec2_tag: resource={{ item.1.id }} region={{ machine_region }} state=present
  with_together:
  - instances
  - ec2.instances
  args:
    tags:
      Name: "{{ item.0 }}"

- set_fact:
    instance_groups: tag_created-by_{{ created_by }}, tag_env_{{ env }}, tag_host-type_{{ host_type }}, tag_env-host-type_{{ env_host_type }}

- name: Add new instances groups and variables
  add_host:
    hostname: "{{ item.0 }}"
    ansible_ssh_host: "{{ item.1.dns_name }}"
    groups: "{{ instance_groups }}"
    ec2_private_ip_address: "{{ item.1.private_ip }}"
    ec2_ip_address: "{{ item.1.public_ip }}"
  with_together:
  - instances
  - ec2.instances

- name: Wait for ssh
  wait_for: "port=22 host={{ item.dns_name }}"
  with_items: ec2.instances

- name: Wait for root user setup
  command: "ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null root@{{ item.dns_name }} echo root user is setup"
  register: result
  until: result.rc == 0
  retries: 20
  delay: 10
  with_items: ec2.instances