summaryrefslogtreecommitdiffstats
path: root/playbooks/gcp/openshift-cluster/build_image.yml
blob: 787de8ebc15943fef0b3914c645cd67f15244600 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
- name: Verify prerequisites for image build
  hosts: localhost
  connection: local
  gather_facts: no
  tasks:
  - name: Require openshift_gcp_base_image
    fail:
      msg: "A base image name or family is required for image building.  Please ensure `openshift_gcp_base_image` is defined."
    when: openshift_gcp_base_image is undefined

- name: Launch image build instance
  hosts: localhost
  connection: local
  gather_facts: no
  tasks:
  - name: Set facts
    set_fact:
      openshift_node_bootstrap: True
      openshift_master_unsupported_embedded_etcd: True

  - name: Create the image instance disk
    gce_pd:
      service_account_email: "{{ (lookup('file', openshift_gcp_iam_service_account_keyfile ) | from_json ).client_email }}"
      credentials_file: "{{ openshift_gcp_iam_service_account_keyfile }}"
      project_id: "{{ openshift_gcp_project }}"
      zone: "{{ openshift_gcp_zone }}"
      name: "{{ openshift_gcp_prefix }}build-image-instance"
      disk_type: pd-ssd
      image: "{{ openshift_gcp_base_image }}"
      size_gb: 10
      state: present

  - name: Launch the image build instance
    gce:
      service_account_email: "{{ (lookup('file', openshift_gcp_iam_service_account_keyfile ) | from_json ).client_email }}"
      credentials_file: "{{ openshift_gcp_iam_service_account_keyfile }}"
      project_id: "{{ openshift_gcp_project }}"
      zone: "{{ openshift_gcp_zone }}"
      machine_type: n1-standard-1
      instance_names: "{{ openshift_gcp_prefix }}build-image-instance"
      state: present
      tags:
      - build-image-instance
      disk_auto_delete: false
      disks:
      - "{{ openshift_gcp_prefix }}build-image-instance"
    register: gce

  - name: add host to nodes
    add_host:
      hostname: "{{ item.public_ip }}"
      groupname: nodes
    with_items: "{{ gce.instance_data }}"

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

- hosts: nodes
  tasks:
  - name: Set facts
    set_fact:
      openshift_node_bootstrap: True

# This is the part that installs all of the software and configs for the instance
# to become a node.
- import_playbook: ../../openshift-node/private/image_prep.yml

# Add additional GCP specific behavior
- hosts: nodes
  tasks:
  - include_role:
      name: openshift_gcp
      tasks_from: node_cloud_config.yml
  - include_role:
      name: openshift_gcp
      tasks_from: frequent_log_rotation.yml

- name: Commit image
  hosts: localhost
  connection: local
  tasks:
  - name: Terminate the image build instance
    gce:
      service_account_email: "{{ (lookup('file', openshift_gcp_iam_service_account_keyfile ) | from_json ).client_email }}"
      credentials_file: "{{ openshift_gcp_iam_service_account_keyfile }}"
      project_id: "{{ openshift_gcp_project }}"
      zone: "{{ openshift_gcp_zone }}"
      instance_names: "{{ openshift_gcp_prefix }}build-image-instance"
      state: absent
  - name: Save the new image
    command: gcloud --project "{{ openshift_gcp_project}}" compute images create "{{ openshift_gcp_image_name | default(openshift_gcp_image + '-' + lookup('pipe','date +%Y%m%d-%H%M%S')) }}" --source-disk "{{ openshift_gcp_prefix }}build-image-instance" --source-disk-zone "{{ openshift_gcp_zone }}" --family "{{ openshift_gcp_image }}"
  - name: Remove the image instance disk
    gce_pd:
      service_account_email: "{{ (lookup('file', openshift_gcp_iam_service_account_keyfile ) | from_json ).client_email }}"
      credentials_file: "{{ openshift_gcp_iam_service_account_keyfile }}"
      project_id: "{{ openshift_gcp_project }}"
      zone: "{{ openshift_gcp_zone }}"
      name: "{{ openshift_gcp_prefix }}build-image-instance"
      state: absent