-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathadhoc-provision-ocp4-kvm-guest.yml
executable file
·117 lines (109 loc) · 4.3 KB
/
adhoc-provision-ocp4-kvm-guest.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
#!/usr/bin/env ansible-playbook
---
# This playbook is an ad-hoc task used to deploy kvm nodes for OCP4
# It used the following variables, declared through inventory (group/host vars):
# rhcos_version: 4.5.6 # upstream version to fetch from mirror.openshift.com in local httpd dir for deployment
# rhcos_install_img_url: # Where to grab rhcos install http://<host>/<path>/rhcos/rhcos-4.3.8-x86_64-metal.x86_64.raw.gz
# rhcos_ignition_file_url: # where to find ignition file http://<host>/config/rhcos/bootstrap.ign #to be modified based on group or host level, for bootstrap, master, etc
# rhcos_install_url: #where kernel/initrd.img and .treeinfo are to be found, internal
# kvm_guest_vcpus:
# kvm_guest_memory:
# kvm_guest_disk_size: #in GiB, not to be added, so example: 120
# kvm_host_bridge: # which defined bridged to use for the guest vnic
# kvm_guest_vnic: ens3
# ip:
# nameservers:
# - 192.168.1.1
# - 192.168.2.2
# gateway
# deploy_host: # http server serving ignition files
- hosts: "{{ ocp_init_hosts }}"
become: true
gather_facts: false
vars_prompt:
- name: "ocp_init_hosts"
prompt: "[WARNING] KVM guest to be installed with OCP => "
private: no
tasks:
- block:
- name: == OCP KVM provisioning == Ensuring we have needed httpd dir
file:
path: "/var/www/html/repo/ocp/"
state: directory
mode: 0755
- name: == OCP KVM provisioning == Importing generated Ignition files
template:
src: "{{ filestore }}/rhcos/{{ item }}"
dest: "/var/www/html/repo/ocp/{{ item }}"
mode: 0755
with_items:
- bootstrap.ign
- master.ign
- worker.ign
- name: == OCP KVM provisioning == Downloading RHCOS deploy files
get_url:
dest: /var/www/html/repo/ocp/
mode: 0755
url: "https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/latest/{{ rhcos_version }}/{{ item }}"
run_once: True
with_items:
- "rhcos-{{ rhcos_version }}-x86_64-live-initramfs.x86_64.img"
- "rhcos-{{ rhcos_version }}-x86_64-live-kernel-x86_64"
- "rhcos-{{ rhcos_version }}-x86_64-live-rootfs.x86_64.img"
- "rhcos-{{ rhcos_version }}-x86_64-metal.x86_64.raw.gz"
- name: == OCP KVM provisioning == Ensuring symlink for correct version {{ rhcos_version }}
file:
state: link
src: "/var/www/html/repo/ocp/rhcos-{{ rhcos_version }}-x86_64-metal.x86_64.raw.gz"
dest: "/var/www/html/repo/ocp/rhcos-metal.raw"
- name: == OCP KVM provisioning == Creating needed treeinfo for virt-install --location
template:
src: ocp-treeinfo.j2
dest: /var/www/html/repo/ocp/.treeinfo
mode: 0644
delegate_to: "{{ deploy_host }}"
tags:
- ignition
- repo
- name: == OCP KVM provisioning == Checking OCP Virtual Guest exist[s]
virt:
name: "{{ inventory_hostname }}"
state: running
ignore_errors: yes
no_log: True
delegate_to: "{{ kvm_host }}"
register: vm_exists
tags:
- kvm_deploy
- name: == OCP KVM provisioning == Creating temporary virt-install command
template:
src: ../templates/ansible-virt-install-ocp.j2
dest: "/var/lib/libvirt/virt-install-{{ inventory_hostname }}"
mode: 0750
owner: root
group: root
delegate_to: "{{ kvm_host }}"
tags:
- kvm_deploy
- name: == OCP KVM provisioning == Deploying the OCP Virtual Guest[s]
command: "/var/lib/libvirt/virt-install-{{ inventory_hostname }}"
when: vm_exists is failed
delegate_to: "{{ kvm_host }}"
tags:
- kvm_deploy
- name: == OCP KVM provisioning == Waiting for sshd to be available on the deployed node
wait_for:
port: 22
host: "{{ ip }}"
timeout: 1200
delegate_to: "{{ deploy_host }}"
when: vm_exists is failed
tags:
- kvm_deploy
- name: == OCP KVM provisioning == Ensuring we remove the templatized virt-install script
file:
path: "/var/lib/libvirt/virt-install-{{ inventory_hostname }}"
state: absent
delegate_to: "{{ kvm_host }}"
tags:
- kvm_deploy