-
Notifications
You must be signed in to change notification settings - Fork 39
/
07_vm_provisioning_ocp.yml
140 lines (133 loc) · 5.84 KB
/
07_vm_provisioning_ocp.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
- name: This play provisions OCP VMs based on intial config
hosts: vm_host
vars_files:
- vars/cluster_vars.yml
- vars/infra_vars.yml
tasks:
- name: Provision bootstrap node with Terraform
community.general.terraform:
force_init: true
project_path: "{{ workspace_directory.base_path }}/{{ cluster.name }}/terraform/bootstrap"
variables:
hostname: "bootstrap"
libvirt_network: "{{ cluster.name }}"
libvirt_pool: "{{ cluster.name }}"
cpu: "{{ cluster_nodes.specs.bootstrap.vcpu }}"
vm_volume_size: "{{ cluster_nodes.specs.bootstrap.disk }}"
memory: "{{ cluster_nodes.specs.bootstrap.mem }}"
state: present
become: true
register: output_bootstrap
- name: Provision master nodes with Terraform
community.general.terraform:
project_path: "{{ workspace_directory.base_path }}/{{ cluster.name }}/terraform/masters"
force_init: true
variables:
hostname: "master"
libvirt_network: "{{ cluster.name }}"
libvirt_pool: "{{ cluster.name }}"
cpu: "{{ cluster_nodes.specs.masters.vcpu }}"
memory: "{{ cluster_nodes.specs.masters.mem }}"
vm_volume_size: "{{ cluster_nodes.specs.masters.disk }}"
vm_count: "{{ cluster_nodes.host_list.masters | count }}"
vm_block_device: "{{ cluster.additional_block_device.enabled if three_node else false }}"
vm_block_device_size: "{{ cluster.additional_block_device.size }}"
vm_additional_nic: "{{ cluster.additional_nic.enabled | default(false, true) }}"
vm_additional_nic_network: "{{ cluster.additional_nic.network | default(cluster.name, true) }}"
state: present
become: true
register: output_masters
- name: Provision worker nodes with Terraform
community.general.terraform:
project_path: "{{ workspace_directory.base_path }}/{{ cluster.name }}/terraform/workers"
force_init: true
variables:
hostname: "worker"
libvirt_network: "{{ cluster.name }}"
libvirt_pool: "{{ cluster.name }}"
cpu: "{{ cluster_nodes.specs.workers.vcpu }}"
memory: "{{ cluster_nodes.specs.workers.mem }}"
vm_volume_size: "{{ cluster_nodes.specs.workers.disk }}"
vm_count: "{{ cluster_nodes.host_list.workers | count }}"
vm_block_device: "{{ cluster.additional_block_device.enabled | default(false, true) }}"
vm_block_device_size: "{{ cluster.additional_block_device.size }}"
vm_additional_nic: "{{ cluster.additional_nic.enabled | default(false, true) }}"
vm_additional_nic_network: "{{ cluster.additional_nic.network | default(cluster.name, true) }}"
state: present
become: true
register: output_workers
when: not three_node
- name: Add bootstrap node and set vars
ansible.builtin.add_host:
hostname: "bootstrap"
node_hostname: "bootstrap"
node_mac: "{{ output_bootstrap.outputs.macs.value[0] | lower }}"
node_ip: "{{ item.ip }}"
node_reversedns: "{{ item.ip | ansible.utils.ipaddr('revdns') }}" # noqa jinja[invalid]
node_role: "bootstrap"
node_fqdn: bootstrap.{{ ocp_domain }}
groups:
- "bootstrap"
loop: "{{ cluster_nodes.host_list.bootstrap }}"
- name: Add masters to correct group and set facts
ansible.builtin.add_host:
hostname: "master-{{ master_idx }}"
node_hostname: "master-{{ master_idx }}"
etcd_fqdn: "etcd-{{ master_idx }}.{{ ocp_domain }}"
etcd_ip: "{{ item.ip }}"
node_mac: "{{ output_masters.outputs.macs.value[master_idx] | lower }}" # noqa jinja[invalid]
node_ip: "{{ item.ip }}"
node_reversedns: "{{ item.ip | ansible.utils.ipaddr('revdns') }}"
node_role: "master"
node_fqdn: master-{{ master_idx }}.{{ ocp_domain }}
groups:
- "masters"
loop: "{{ cluster_nodes.host_list.masters }}"
loop_control:
index_var: master_idx
when: not three_node
- name: Add masters to correct group and set facts
ansible.builtin.add_host:
hostname: "master-{{ master_idx }}"
node_hostname: "master-{{ master_idx }}"
etcd_fqdn: "etcd-{{ master_idx }}.{{ ocp_domain }}"
etcd_ip: "{{ item.ip }}"
node_mac: "{{ output_masters.outputs.macs.value[master_idx] | lower }}" # noqa jinja[invalid]
node_ip: "{{ item.ip }}"
node_reversedns: "{{ item.ip | ansible.utils.ipaddr('revdns') }}"
node_role: "master"
node_fqdn: master-{{ master_idx }}.{{ ocp_domain }}
groups:
- "masters"
- "workers"
loop: "{{ cluster_nodes.host_list.masters }}"
loop_control:
index_var: master_idx
when: three_node
- name: Add workers to correct group and set facts
ansible.builtin.add_host:
hostname: "worker-{{ worker_idx }}"
node_hostname: "worker-{{ worker_idx }}"
node_mac: "{{ output_workers.outputs.macs.value[worker_idx] | lower }}" # noqa jinja[invalid]
node_ip: "{{ item.ip }}"
node_reversedns: "{{ item.ip | ansible.utils.ipaddr('revdns') }}"
node_role: "worker"
ocp_role: "{{ item.role | default('worker') }}"
node_fqdn: worker-{{ worker_idx }}.{{ ocp_domain }}
groups:
- "workers"
loop: "{{ cluster_nodes.host_list.workers }}"
loop_control:
index_var: worker_idx
when: not three_node
- name: Run dynamic inventory creation for infra nodes
when: not three_node
block:
- name: Add infra nodes to correct group and set facts
ansible.builtin.add_host:
hostname: "{{ item }}"
groups:
- "infra"
loop: "{{ groups['workers'] }}"
when:
- hostvars[item].ocp_role == 'infra'