-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharo4-deploy.yml
168 lines (145 loc) · 7.27 KB
/
aro4-deploy.yml
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
163
164
165
166
167
# Ansible Deployment Playbook
# Azure Red Hat OpenShift 4.x
#
# Written by: Stuart Kirk <[email protected]>
# With contributions by: Haiyuan Zhang <[email protected]>, Fred Sun <[email protected]> & Zim Kalinowski <[email protected]>
#
# Notes:
# * Ansible's service principal must be an owner on the subscription in question - Contributor is not high enough access
# * A service principal with Contributor permission on the active subscription must be used below which can be obtained from the Azure Linux CLI
# * Pull secret must be read from a file due to the hidden characters that are placed inside a variable, including a carriage return, which will cause the deploy to fail
# * You must populate the contents of aro4-secrets.yml
#
# To be fixed:
#
# ISSUE FILED https://github.com/ansible-collections/azure/issues/266
# ARO-RP role assignment cant already exist on VNET otherwise azure_rm_roleassignment module will fail - idempotency failure
#
# ISSUE FILED https://github.com/ansible-collections/azure/issues/267
# Worker node count must be an integer; Playbook will error if you use '' or "" to indicate a string. Thus you can also not set this in a variable and it must be hard-coded in the task
#
# ISSUE FILED https://github.com/ansible-collections/azure/issues/270
# Ingress profile must be named "default" - any other name will not work - Is it even necessary to have this declared in the playbook?
# Why are ingress profiles defined as a list, however api profiles are not in the module?
#
# ISSUE FILED https://github.com/ansible-collections/azure/issues/268
# API & Ingress privacy must be "Public" or "Private" - case sensitive -- API privacy will revert to "Public" even if the variable is set to "Private" - needs to be fixed
#
# ISSUE FILED https://github.com/ansible-collections/azure/issues/269
# Custom domain value does not work when set and cannot be null variable
#
# ------------------------------------------------------------------------------------------------------
- name: Deploy Azure Red Hat OpenShift 4.x
hosts: localhost
connection: local
collections:
- azure.azcollection
vars_files:
- ./aro4-secrets.yml
vars:
########################################################## You may change any of these variables.
aro_master_subnet: "AROMasterSubnet"
aro_master_subnet_cidr: "100.100.10.0/24"
aro_vnet: "AROVNet"
aro_vnet_cidr: "100.100.0.0/16"
aro_worker_subnet: "AROWorkerSubnet"
aro_worker_subnet_cidr: "100.100.20.0/24"
azure_dc: "eastus"
cluster_name: "aro4-ansible-build"
cluster_pull_secret: "{{ lookup('file', '~/openshift/aro4/pull-secret.txt') }}"
# customdns: "aro.mydomain.com"
master_vm_size: "Standard_D8s_v3"
network_pod_cidr: "10.128.0.0/14"
network_service_cidr: "172.30.0.0/16"
privacy_api: "Public"
privacy_ingress: "Public"
resource_group: "aro4-ansible"
worker_node_count: "4"
worker_vm_size: "Standard_D4s_v3"
tasks:
- name: Creating ARO Resource Group
azure.azcollection.azure_rm_resourcegroup:
name: "{{ resource_group }}"
location: "{{ azure_dc }}"
- name: Creating ARO Virtual Network
azure.azcollection.azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"
name: "{{ aro_vnet }}"
address_prefixes: "{{ aro_vnet_cidr }}"
- name: Creating ARO 'Master' Subnet
azure.azcollection.azure_rm_subnet:
resource_group: "{{ resource_group }}"
name: "{{ aro_master_subnet }}"
address_prefix: "{{ aro_master_subnet_cidr }}"
virtual_network: "{{ aro_vnet }}"
private_link_service_network_policies: Disabled
service_endpoints:
- service: Microsoft.ContainerRegistry
- name: Creating ARO 'Worker' Subnet
azure.azcollection.azure_rm_subnet:
resource_group: "{{ resource_group }}"
name: "{{ aro_worker_subnet }}"
address_prefix: "{{ aro_worker_subnet_cidr }}"
virtual_network: "{{ aro_vnet }}"
service_endpoints:
- service: Microsoft.ContainerRegistry
- name: Obtain ARO Resource Group Role Definition Scope
azure.azcollection.azure_rm_roledefinition_info:
scope: "/subscriptions/{{ lookup('env', 'AZURE_SUBSCRIPTION_ID') }}/resourceGroups/{{ resource_group }}"
register: rg_roledef_scope_output
- name: Obtain Object ID of Contributor Role Definition
set_fact:
fact: "{{ rg_roledef_scope_output | json_query(jmesquery) }}"
register: oid_rg_scope_query
vars:
jmesquery: "roledefinitions[?role_name == 'Contributor'].[id]"
- name: Setting Object ID scope variable for the ARO Resource Group
set_fact:
rg_oid: "{{ oid_rg_scope_query.ansible_facts.fact[0][0] }}"
- name: Granting the ARO Resource Provider Contributor access to the ARO virtual network
azure.azcollection.azure_rm_roleassignment:
scope: "/subscriptions/{{ lookup('env', 'AZURE_SUBSCRIPTION_ID') }}/resourceGroups/{{ resource_group }}/providers/Microsoft.Network/virtualNetworks/{{ aro_vnet }}"
assignee_object_id: "{{ rp_oid }}"
role_definition_id: "{{ rg_oid }}"
- name: Granting the ARO AAD Application Object ID Contributor access to the ARO virtual network
azure.azcollection.azure_rm_roleassignment:
scope: "/subscriptions/{{ lookup('env', 'AZURE_SUBSCRIPTION_ID') }}/resourceGroups/{{ resource_group }}/providers/Microsoft.Network/virtualNetworks/{{ aro_vnet }}"
assignee_object_id: "{{ app_oid }}"
role_definition_id: "{{ rg_oid }}"
- name: Create Azure Red Hat OpenShift 4 Cluster
azure_rm_openshiftmanagedcluster:
resource_group: "{{ resource_group }}"
name: "{{ cluster_name }}"
location: "{{ azure_dc }}"
api_server_profile:
visibility: "{{ privacy_api }}"
# cluster_profile:
# pull_secret: "{{ cluster_pull_secret }}"
# domain: "{{ customdns }}"
ingress_profiles:
- name: "default"
visibility: "{{ privacy_ingress }}"
master_profile:
vm_size : "{{ master_vm_size }}"
subnet_id: "/subscriptions/{{ lookup('env', 'AZURE_SUBSCRIPTION_ID') }}/resourceGroups/{{resource_group}}/providers/Microsoft.Network/virtualNetworks/{{ aro_vnet }}/subnets/{{ aro_master_subnet }}"
network_profile:
pod_cidr: "{{ network_pod_cidr }}"
service_cidr: "{{ network_service_cidr }}"
service_principal_profile:
client_id: "{{ sp_client_id }}"
client_secret: "{{ sp_secret }}"
worker_profiles:
- name: "worker"
vm_size : "{{ worker_vm_size }}"
subnet_id: "/subscriptions/{{ lookup('env', 'AZURE_SUBSCRIPTION_ID') }}/resourceGroups/{{resource_group}}/providers/Microsoft.Network/virtualNetworks/{{ aro_vnet }}/subnets/{{ aro_worker_subnet }}"
# count: "{{ worker_node_count }}"
count: 4
- debug:
msg: "Azure Red Hat OpenShift takes roughly 30-40 minutes to provision."
- debug:
msg: "Cluster IP credentials can be obainted with: az aro show -n {{ cluster_name }} -g {{ resource_group }} -o jsonc --query '[apiserverProfile , consoleProfile , ingressProfiles]'"
- debug:
msg: "Kubeadmin credentials can be obtained with: az aro list-credentials -n {{ cluster_name }} -g {{ resource_group }} -o table"
- debug:
msg: "You can also view the cluster build status with: az aro list"
# - end