blob: 75d0ddf9d98dfa404e532410b5bd5f09f43b698f (
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
---
# This playbook ensures that a base image is up to date with all of the required settings
- name: Launch image build instance
hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Require openshift_gcp_root_image
fail:
msg: "A root OS image name or family is required for base image building. Please ensure `openshift_gcp_root_image` is defined."
when: openshift_gcp_root_image is undefined
- 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_root_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
- add_host:
hostname: "{{ item.public_ip }}"
groupname: build_instance_ips
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 }}"
- name: Prepare instance content sources
pre_tasks:
- set_fact:
allow_rhel_subscriptions: "{{ rhsub_skip | default('no', True) | lower in ['no', 'false'] }}"
- set_fact:
using_rhel_subscriptions: "{{ (deployment_type in ['enterprise', 'atomic-enterprise', 'openshift-enterprise'] or ansible_distribution == 'RedHat') and allow_rhel_subscriptions }}"
hosts: build_instance_ips
roles:
- role: rhel_subscribe
when: using_rhel_subscriptions
- role: openshift_repos
vars:
openshift_additional_repos: []
post_tasks:
- name: Add custom repositories
include_role:
name: openshift_gcp
tasks_from: add_custom_repositories.yml
- name: Add the Google Cloud repo
yum_repository:
name: google-cloud
description: Google Cloud Compute
baseurl: https://packages.cloud.google.com/yum/repos/google-cloud-compute-el7-x86_64
gpgkey: https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
gpgcheck: yes
repo_gpgcheck: yes
state: present
when: ansible_os_family == "RedHat"
- name: Add the jdetiber-qemu-user-static copr repo
yum_repository:
name: jdetiber-qemu-user-static
description: QEMU user static COPR
baseurl: https://copr-be.cloud.fedoraproject.org/results/jdetiber/qemu-user-static/epel-7-$basearch/
gpgkey: https://copr-be.cloud.fedoraproject.org/results/jdetiber/qemu-user-static/pubkey.gpg
gpgcheck: yes
repo_gpgcheck: no
state: present
when: ansible_os_family == "RedHat"
- name: Install qemu-user-static
package:
name: qemu-user-static
state: present
- name: Start and enable systemd-binfmt service
systemd:
name: systemd-binfmt
state: started
enabled: yes
- name: Build image
hosts: build_instance_ips
pre_tasks:
- name: Set up core host GCP configuration
include_role:
name: openshift_gcp
tasks_from: configure_gcp_base_image.yml
roles:
- role: os_update_latest
post_tasks:
- name: Disable all repos on RHEL
command: subscription-manager repos --disable="*"
when: using_rhel_subscriptions
- name: Enable repos for packages on RHEL
command: subscription-manager repos --enable="rhel-7-server-rpms" --enable="rhel-7-server-extras-rpms"
when: using_rhel_subscriptions
- name: Install common image prerequisites
package: name={{ item }} state=latest
with_items:
# required by Ansible
- PyYAML
- docker
- google-compute-engine
- google-compute-engine-init
- google-config
- wget
- git
- net-tools
- bind-utils
- iptables-services
- bridge-utils
- bash-completion
- name: Clean yum metadata
command: yum clean all
args:
warn: no
when: ansible_os_family == "RedHat"
- 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_base_image_name | default(openshift_gcp_base_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_base_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
|