diff --git a/playbooks/deploy-ocp-hybrid-multinode.yml b/playbooks/deploy-ocp-hybrid-multinode.yml index 6c14bae..8755174 100644 --- a/playbooks/deploy-ocp-hybrid-multinode.yml +++ b/playbooks/deploy-ocp-hybrid-multinode.yml @@ -143,6 +143,7 @@ vars: oc_client_install_url: "{{ ocp_version_facts_oc_client_pull_link }}" oc_client_install_archive_dest_dir: "{{ dest_iso_dir }}" + oc_clinet_install_version: "{{ ocp_version_facts_parsed_release }}" - name: Download and extract OCP installer ansible.builtin.import_role: diff --git a/playbooks/roles/oc_client_install/README.md b/playbooks/roles/oc_client_install/README.md index e251d29..0d7f068 100644 --- a/playbooks/roles/oc_client_install/README.md +++ b/playbooks/roles/oc_client_install/README.md @@ -11,7 +11,7 @@ This Ansible role automates the installation and management of the OpenShift Cli - Verifies if the `oc_client_install_url` variable is provided. - Checks if `oc` is already installed. - Removes existing `oc` binary if found. -- Downloads and installs the `oc` client from the specified source. +- Downloads and installs the `oc` client either from mirror or from the specified source. - Ensures proper directory structure for the `oc` binary. - Moves both `oc` and `kubectl` binaries to the user's `.local/bin` directory. - Verifies the installation by running `oc version`. @@ -31,6 +31,7 @@ This Ansible role automates the installation and management of the OpenShift Cli | `oc_client_install_url` | URL to download the OpenShift client archive (Required) |yes| | `oc_client_install_archive_dest_dir` | Directory where the archive will be stored |no| | `oc_client_install_archive_name` | Name of the downloaded archive file |no| +| `oc_clinet_install_version` | Specifies the OC client version used for retrieving the archive from the mirror link |no| ### Usage Include this role in your playbook as follows: @@ -67,7 +68,7 @@ Include this role in your playbook as follows: Ensures any previously downloaded archive is removed before downloading. 3. **Download OpenShift Client Archive** - Fetches the `openshift-client-linux.tar.gz` file from the given URL. + Fetches the `openshift-client-linux.tar.gz` file either from the mirror or from the given URL. 4. **Extract Archive** Unpacks the downloaded archive. @@ -103,7 +104,19 @@ None. vars: oc_client_install_url: "https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/latest/openshift-client-linux.tar.gz" ``` - +Example of getting client from the mirror first: +```yaml +- hosts: localhost + gather_facts: no + roles: + - name: Deploy/Redeploy OCP client + ansible.builtin.import_role: + name: oc_client_install + vars: + oc_client_install_url: "https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/latest/" + oc_client_install_archive_dest_dir: "/tmp/client" + oc_clinet_install_version: "4.17.10" +``` ### License Apache diff --git a/playbooks/roles/oc_client_install/tasks/oc_install.yml b/playbooks/roles/oc_client_install/tasks/oc_install.yml index 014beba..cf44827 100644 --- a/playbooks/roles/oc_client_install/tasks/oc_install.yml +++ b/playbooks/roles/oc_client_install/tasks/oc_install.yml @@ -1,8 +1,3 @@ -- name: Make a request to trigger tools extraction - ansible.builtin.uri: - url: "{{ oc_client_install_url.split('/')[:-1] | join('/') }}" - return_content: true - - name: Remove OC client archive and checksum file if exist ansible.builtin.file: state: absent @@ -11,21 +6,72 @@ - "{{ oc_client_install_archive_dest_dir }}/{{ oc_client_install_archive_name }}" - "{{ oc_client_install_archive_dest_dir }}/{{ checksum_file_name }}" -- name: Download checksum file - register: download_result - until: download_result is not failed - retries: 60 - delay: 10 - notify: "Delete checksum file" - ansible.builtin.get_url: - url: "{{ oc_client_install_url.split('/')[:-1] | join('/') }}/{{ checksum_file_name }}" - dest: "{{ oc_client_install_archive_dest_dir }}/{{ checksum_file_name }}" - mode: '0640' +- name: Deploy OC client + block: + - name: Try to download checksum file from mirror + register: download_result + until: download_result is not failed + retries: 3 + delay: 5 + notify: "Delete checksum file" + ansible.builtin.get_url: + url: "{{ mirror_url }}/{{ oc_clinet_install_version }}/{{ checksum_file_name }}" + dest: "{{ oc_client_install_archive_dest_dir }}/{{ checksum_file_name }}" + mode: '0640' -- name: Read checksum file and store content in data variable - ansible.builtin.command: "cat {{ oc_client_install_archive_dest_dir }}/{{ checksum_file_name }}" - changed_when: false - register: data + - name: Read checksum file and store content in data variable + ansible.builtin.command: "cat {{ oc_client_install_archive_dest_dir }}/{{ checksum_file_name }}" + changed_when: false + register: data + + - name: Download openshift-client-linux.tar.gz from mirror + register: download_result + until: download_result is not failed + retries: 3 + delay: 5 + notify: "Delete openshift-client-linux.tar.gz" + vars: + checksum: "{{ data.stdout_lines | select('match', '.*' ~ oc_client_install_url.split('/')[-1] ~ '$') }}" + ansible.builtin.get_url: + url: "{{ mirror_url }}/{{ oc_clinet_install_version }}/openshift-client-linux-{{ oc_clinet_install_version }}.tar.gz" + dest: "{{ oc_client_install_archive_dest_dir }}/{{ oc_client_install_archive_name }}" + mode: '0640' + checksum: "sha256:{{ checksum[0].split(' ')[0] }}" + + rescue: + - name: Make a request to trigger tools extraction + ansible.builtin.uri: + url: "{{ oc_client_install_url.split('/')[:-1] | join('/') }}" + + - name: Download checksum file + register: download_result + until: download_result is not failed + retries: 60 + delay: 10 + notify: "Delete checksum file" + ansible.builtin.get_url: + url: "{{ oc_client_install_url.split('/')[:-1] | join('/') }}/{{ checksum_file_name }}" + dest: "{{ oc_client_install_archive_dest_dir }}/{{ checksum_file_name }}" + mode: '0640' + + - name: Read checksum file and store content in data variable + ansible.builtin.command: "cat {{ oc_client_install_archive_dest_dir }}/{{ checksum_file_name }}" + changed_when: false + register: data + + - name: Download openshift-client-linux.tar.gz + register: download_result + until: download_result is not failed + retries: 60 + delay: 10 + notify: "Delete openshift-client-linux.tar.gz" + vars: + checksum: "{{ data.stdout_lines | select('match', '.*' ~ oc_client_install_url.split('/')[-1] ~ '$') }}" + ansible.builtin.get_url: + url: "{{ oc_client_install_url }}" + dest: "{{ oc_client_install_archive_dest_dir }}/{{ oc_client_install_archive_name }}" + mode: '0640' + checksum: "sha256:{{ checksum[0].split(' ')[0] }}" - name: Print client's archive sha256 vars: @@ -33,20 +79,6 @@ ansible.builtin.debug: msg: "sha256:{{ checksum[0].split(' ')[0] }}" -- name: Download openshift-client-linux.tar.gz - register: download_result - until: download_result is not failed - retries: 60 - delay: 10 - notify: "Delete openshift-client-linux.tar.gz" - vars: - checksum: "{{ data.stdout_lines | select('match', '.*' ~ oc_client_install_url.split('/')[-1] ~ '$') }}" - ansible.builtin.get_url: - url: "{{ oc_client_install_url }}" - dest: "{{ oc_client_install_archive_dest_dir }}/{{ oc_client_install_archive_name }}" - mode: '0640' - checksum: "sha256:{{ checksum[0].split(' ')[0] }}" - - name: Extract archive ansible.builtin.unarchive: src: "{{ oc_client_install_archive_dest_dir }}/{{ oc_client_install_archive_name }}" diff --git a/playbooks/roles/oc_client_install/vars/main.yml b/playbooks/roles/oc_client_install/vars/main.yml index 0cd5430..341e96f 100644 --- a/playbooks/roles/oc_client_install/vars/main.yml +++ b/playbooks/roles/oc_client_install/vars/main.yml @@ -2,3 +2,4 @@ # vars file for oc_client_install oc_client_install_archive_name: openshift-client-linux.tar.gz checksum_file_name: sha256sum.txt +mirror_url: https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp