Skip to content

Commit c9d1e03

Browse files
committed
added deploy-ocp-hybrid-multinode.yml playbook
1 parent 518c92d commit c9d1e03

File tree

18 files changed

+718
-1
lines changed

18 files changed

+718
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
nodes:
2+
children:
3+
masters:
4+
workers:
5+
6+
masters:
7+
hosts:
8+
master0:
9+
master1:
10+
master2:
11+
12+
workers:
13+
hosts:
14+
worker0:
15+
worker1:
16+
worker2:
17+
18+
bastions:
19+
hosts:
20+
bastion:
21+
22+
hypervisors:
23+
hosts:
24+
hypervisor:
25+
26+
vm_hosts:
27+
children:
28+
hypervisors:
+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
## Disclaimer:
2+
# This playbook is not officially supported and comes with no guarantees.
3+
# Use it at your own risk. Ensure you test thoroughly in your environment
4+
# before deploying to production.
5+
6+
# This Ansible playbook is designed for deploying an OpenShift cluster.
7+
# It includes various roles and tasks necessary to configure a bastion host,
8+
# deploy virtual machines (VMs), and boot bare-metal (BM) and VM nodes.
9+
# The playbook also sets up dependencies, generates manifests, and monitors the installation process.
10+
11+
## Overview:
12+
# This playbook automates the process of deploying ocp cluster. It includes:
13+
# - Bastion host setup: Installs required dependencies and extracts OpenShift installer.
14+
# - OCP version facts: Retrieves OpenShift release information.
15+
# - HTTP storage setup: Configures HTTP-based storage for required artifacts.
16+
# - Virtual control plane setup: Enables necessary repositories and configures sushy tools.
17+
# - VM and BM booting: Deploys instances and boots nodes using an agent-based installer.
18+
# - Installation monitoring: Ensures the installation process completes successfully.
19+
20+
## Prerequisites:
21+
# - Ansible 2.10+ installed on the control node.
22+
# - Ansible control node configured with necessary permissions.
23+
# - SSH Access to hypervisors hosts.
24+
# - SSH Access to bastion hosts.
25+
# - ocp version of link to ocp release
26+
# - pre-configured hosts_vars and grup_vars directories
27+
28+
## Roles Requirements
29+
# The playbook uses role:
30+
# - redhatci.ocp.create_vms: Creates VMs on given hypervisor.
31+
32+
# Required Roles:
33+
# The playbook uses roles:
34+
# - ocp_version_facts
35+
# - redhatci.ocp.setup_http_store
36+
# - ocp_client
37+
# - redhatci.ocp.extract_openshift_installer
38+
# - redhatci.ocp.generate_manifests
39+
# - redhatci.ocp.generate_agent_iso
40+
# - redhatci.ocp.process_kvm_nodes
41+
# - redhatci.ocp.setup_sushy_tools
42+
# - redhatci.ocp.destroy_vms
43+
# - redhatci.ocp.create_vms
44+
# - redhatci.ocp.boot_iso
45+
# - redhatci.ocp.monitor_agent_based_installer
46+
47+
## Usage:
48+
# - Ensure all required variables are defined in the inventory or host_vars/group_vars.
49+
# - Execute the playbook using Ansible's command-line tool:
50+
#
51+
# Deploy latest 4.17
52+
# ansible-playbook ./playbooks/deploy-ocp-hybrid-multinode.yml -i ./inventories/ocp-deployment/deploy-ocp-hybrid-multinode.yml --extra-vars 'release=4.17'
53+
# Deploy specific release from link:
54+
# ansible-playbook ./playbooks/deploy-ocp-hybrid-multinode.yml -i ./inventories/ocp-deployment/deploy-ocp-hybrid-multinode.yml
55+
# --extra-vars 'release=quay.io/openshift-release-dev/ocp-release:4.15.44-x86_64'
56+
# Deploy specific version:
57+
# ansible-playbook ./playbooks/deploy-ocp-hybrid-multinode.yml -i ./inventories/ocp-deployment/deploy-ocp-hybrid-multinode.yml --extra-vars 'release=4.17.9'
58+
#
59+
# Notes:
60+
# - This playbook assumes the hypervisor and bastion hosts are pre-installed and ready.
61+
# - Test in a non-production environment before deploying.
62+
---
63+
- name: Setup bastion environment and generate manifests for cluster deployment
64+
hosts: bastion
65+
vars:
66+
release: "4.17"
67+
tasks:
68+
69+
- name: Set openshift-installer path fact
70+
ansible.builtin.set_fact:
71+
openshift_installer_extract_dest_path: "{{ dest_iso_dir }}/wip/extract"
72+
73+
- name: Install dependencies required for the installer
74+
become: true
75+
ansible.builtin.dnf:
76+
name:
77+
- nmstate
78+
state: present
79+
80+
- name: Ensure firewalld is running
81+
become: true
82+
ansible.builtin.service:
83+
name: firewalld
84+
state: started
85+
86+
# The role below sets follwing facts. Please note values are just examples
87+
# ocp_version_facts_pull_spec: quay.io/openshift-release-dev/ocp-release:4.15.44-x86_64
88+
# ocp_version_facts_parsed_release: "4.15.44"
89+
# ocp_version_facts_major: "4"
90+
# ocp_version_facts_minor: "15"
91+
# ocp_version_facts_oc_client_pull_link:
92+
# "https://openshift-release-artifacts.apps.ci.l2s4.p1.openshiftapps.com/4.15.44/openshift-client-linux-4.15.44.tar.gz"
93+
# ocp_version_facts_z_stream: "44"
94+
# ocp_version_facts_dev_version: "rc1"
95+
- name: Set OCP version facts
96+
ansible.builtin.import_role:
97+
name: ocp_version_facts
98+
vars:
99+
ocp_version_facts_release: "{{ release }}"
100+
101+
- name: Setup HTTP storage
102+
ansible.builtin.import_role:
103+
name: redhatci.ocp.setup_http_store
104+
105+
- name: Deploy/Redeploy OC client
106+
ansible.builtin.import_role:
107+
name: ocp_client
108+
vars:
109+
ocp_client_url: "{{ ocp_version_facts_oc_client_pull_link }}"
110+
ocp_client_archive_dest_dir: "{{ dest_iso_dir }}"
111+
112+
- name: Download and extract OCP installer
113+
ansible.builtin.import_role:
114+
name: redhatci.ocp.extract_openshift_installer
115+
vars:
116+
openshift_version: "{{ ocp_version_facts_parsed_release }}"
117+
release_image: "{{ ocp_version_facts_pull_spec }}"
118+
extract_dest_path: "{{ openshift_installer_extract_dest_path }}"
119+
120+
- name: Generate deployment manifests for OCP installation
121+
ansible.builtin.import_role:
122+
name: redhatci.ocp.generate_manifests
123+
124+
- name: Generate boot ISO for agent-based installer
125+
ansible.builtin.import_role:
126+
name: redhatci.ocp.generate_agent_iso
127+
vars:
128+
gai_cluster_name: "{{ cluster_name }}"
129+
gai_repo_root_path: "{{ repo_root_path }}"
130+
gai_pull_secret: "{{ pull_secret }}"
131+
gai_agent_based_installer_path: "{{ openshift_installer_extract_dest_path }}/openshift-install"
132+
gai_discovery_iso_name: "agent.iso"
133+
gai_remote_http_src: true
134+
gai_http_delegate_host: "{{ inventory_hostname }}"
135+
136+
- name: Process KVM nodes to set facts
137+
ansible.builtin.import_role:
138+
name: redhatci.ocp.process_kvm_nodes
139+
140+
- name: Setup Virtual Control Plane
141+
hosts: vm_hosts
142+
tasks:
143+
144+
- name: Enable CRB repository
145+
become: true
146+
ansible.builtin.command: "dnf config-manager --enable rhosp-rhel-9.4-crb"
147+
changed_when: false
148+
149+
- name: Setup sushy tool to emulate OOB interface
150+
ansible.builtin.import_role:
151+
name: redhatci.ocp.setup_sushy_tools
152+
vars:
153+
cert_state: "QE"
154+
cert_locality: TLV
155+
cert_organization: RH
156+
cert_country: US
157+
cert_organizational_unit: QE
158+
fetched_dest: "/tmp/artifacts"
159+
160+
- name: Destroy pre-installed VMs
161+
ansible.builtin.import_role:
162+
name: redhatci.ocp.destroy_vms
163+
164+
- name: Create VMs
165+
ansible.builtin.import_role:
166+
name: redhatci.ocp.create_vms
167+
168+
- name: Boot Bare-Metal Nodes
169+
hosts: workers
170+
gather_facts: false
171+
tasks:
172+
- name: Boot ISO
173+
ansible.builtin.import_role:
174+
name: redhatci.ocp.boot_iso
175+
vars:
176+
boot_iso_url: "http://{{ hostvars['bastion']['ansible_default_ipv4']['address'] }}/{{ agent_iso_name }}"
177+
178+
- name: Boot Virtual Machines
179+
hosts: masters
180+
gather_facts: false
181+
serial: 1
182+
tasks:
183+
- name: Boot ISO
184+
ansible.builtin.import_role:
185+
name: redhatci.ocp.boot_iso
186+
vars:
187+
boot_iso_url: "http://{{ hostvars['bastion']['ansible_default_ipv4']['address'] }}/{{ agent_iso_name }}"
188+
189+
- name: Monitor installation process of agent-based installer
190+
hosts: bastion
191+
gather_facts: false
192+
tasks:
193+
194+
- name: Monitor agent based installation
195+
ansible.builtin.import_role:
196+
name: redhatci.ocp.monitor_agent_based_installer
197+
vars:
198+
agent_based_installer_path: "{{ openshift_installer_extract_dest_path }}/openshift-install"
199+
mabi_retry_install_complete_check: true

playbooks/roles/ocp_client/README.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
## OpenShift Client (OC) Installation Ansible Role
2+
3+
## Disclaimer
4+
This role is provided as-is, without any guarantees of support or maintenance.
5+
The author or contributors are not responsible for any issues arising from the use of this role. Use it at your own discretion.
6+
7+
### Overview
8+
This Ansible role automates the installation and management of the OpenShift Client (`oc`). It verifies if the client is installed, removes any existing versions, and deploys the latest specified version.
9+
10+
### Features
11+
- Verifies if the `ocp_client_url` variable is provided.
12+
- Checks if `oc` is already installed.
13+
- Removes existing `oc` binary if found.
14+
- Downloads and installs the `oc` client from the specified source.
15+
- Ensures proper directory structure for the `oc` binary.
16+
- Moves both `oc` and `kubectl` binaries to the user's `.local/bin` directory.
17+
- Verifies the installation by running `oc version`.
18+
19+
### Requirements
20+
- Ansible 2.9+
21+
- Supported Platforms:
22+
- RHEL 7/8
23+
- CentOS 7/8
24+
- Fedora
25+
- Ubuntu/Debian
26+
27+
### Role Variables
28+
29+
| Variable | Description | Required|
30+
|----------|-------------|---------|
31+
| `ocp_client_url` | URL to download the OpenShift client archive (Required) |yes|
32+
| `ocp_client_archive_dest_dir` | Directory where the archive will be stored |no|
33+
| `ocp_client_archive_name` | Name of the downloaded archive file |no|
34+
35+
### Usage
36+
Include this role in your playbook as follows:
37+
38+
```yaml
39+
- hosts: localhost
40+
gather_facts: no
41+
roles:
42+
- role: ocp_client_installation
43+
vars:
44+
ocp_client_url: "https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/latest/openshift-client-linux.tar.gz"
45+
```
46+
47+
### Tasks Description
48+
49+
#### `main.yml`
50+
1. **Verify Client URL is Provided**
51+
Ensures the `ocp_client_url` variable is set; otherwise, the role fails.
52+
53+
2. **Check if `oc` is Installed**
54+
Runs `which oc` to determine if the `oc` binary is already present.
55+
56+
3. **Remove Pre-existing `oc` Client**
57+
Includes `oc_remove.yml` to find and remove any existing `oc` binaries.
58+
59+
4. **Deploy `oc` Client**
60+
Includes `oc_install.yml` to download, extract, and install the `oc` client.
61+
62+
#### `oc_install.yml`
63+
1. **Trigger Tools Extraction**
64+
Makes a request to the base URL of the provided OpenShift client URL.
65+
66+
2. **Remove Pre-existing Archive**
67+
Ensures any previously downloaded archive is removed before downloading.
68+
69+
3. **Download OpenShift Client Archive**
70+
Fetches the `openshift-client-linux.tar.gz` file from the given URL.
71+
72+
4. **Extract Archive**
73+
Unpacks the downloaded archive.
74+
75+
5. **Ensure Required Directories Exist**
76+
Creates `~/.local/bin` if it does not exist.
77+
78+
6. **Move `oc` and `kubectl` Binaries**
79+
Moves extracted binaries to `~/.local/bin`.
80+
81+
7. **Verify Installation**
82+
Runs `oc version` to confirm the binary is correctly installed and executable.
83+
84+
8. **Fail if `oc` is Missing**
85+
Aborts execution if `oc` is not found or not executable.
86+
87+
#### `oc_remove.yml`
88+
1. **Search for Existing `oc` Binaries**
89+
Searches common directories (`/usr/local/bin`, `/usr/bin`, `/opt/bin`, `~/.local/bin`, `/tmp`) for `oc` binaries.
90+
91+
2. **Remove Existing `oc` Binaries**
92+
Deletes all found `oc` binaries to ensure a fresh installation.
93+
94+
### Dependencies
95+
None.
96+
97+
### Example Playbook
98+
```yaml
99+
- hosts: localhost
100+
gather_facts: no
101+
roles:
102+
- role: ocp_client_installation
103+
vars:
104+
ocp_client_url: "https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/latest/openshift-client-linux.tar.gz"
105+
```
106+
107+
### License
108+
Apache
109+
110+
### Author Information
111+
This role was created by Nikita Kononov.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
# defaults file for ocp_client
3+
ocp_client_archive_dest_dir: /tmp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
# handlers file for ocp_client
3+
- name: Delete openshift-client-linux.tar.gz
4+
ansible.builtin.file:
5+
state: absent
6+
path: "{{ ocp_client_archive_dest_dir }}/{{ ocp_client_archive_name }}"
7+
8+
- name: Delete checksum file
9+
ansible.builtin.file:
10+
state: absent
11+
path: "{{ ocp_client_archive_dest_dir }}/{{ checksum_file_name }}"
12+
13+
- name: Delete oc and kubectl binaries from temp directory
14+
ansible.builtin.file:
15+
path: "{{ ocp_client_archive_dest_dir }}/{{ item }}"
16+
state: absent
17+
loop:
18+
- "oc"
19+
- "kubectl"
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
galaxy_info:
2+
author: Nikita Kononov
3+
description: >
4+
This Ansible role automates the installation and management of the OpenShift Client (`oc`). It verifies if the client is installed,
5+
removes any existing versions, and deploys the latest specified version.
6+
**Disclaimer:** This role is provided as-is, without any guarantees of support or maintenance.
7+
company: Red Hat
8+
license: Apache-2.0
9+
standalone: true
10+
min_ansible_version: "2.9"
11+
galaxy_tags:
12+
- oc
13+
- occlient
14+
- ocinstallation
15+
16+
dependencies: []

0 commit comments

Comments
 (0)