Skip to content

Instantly share code, notes, and snippets.

@kameshsampath
Created July 20, 2020 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kameshsampath/5f8ca6c537cc2412c562412d9a7cff2d to your computer and use it in GitHub Desktop.
Save kameshsampath/5f8ca6c537cc2412c562412d9a7cff2d to your computer and use it in GitHub Desktop.
#!/usr/bin/env ansible-playbook -c local
---
- hosts: localhost
connection: local
vars:
ocp_version: 4.5.2
okd_image: quay.io/openshift/okd:4.5.0-0.okd-2020-07-14-153706-ga
tasks:
- set_fact:
ocp_bin_dir: "{{ansible_env.HOME}}/openshift/bin"
- set_fact:
okd_bin_dir: "{{ansible_env.HOME}}/openshift/okd/bin"
- name: Make sure destination exists
file:
path: "{{item}}"
state: directory
mode: 0755
with_items:
- "{{ocp_bin_dir}}"
- "{{okd_bin_dir}}"
- name: Set Linux Downloadables
set_fact:
download_files:
- "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux-{{ocp_version}}.tar.gz"
- "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-install-linux-{{ocp_version}}.tar.gz"
# - "https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-linux-amd64.tar.gz"
when: ansible_os_family == "RedHat" or ansible_os_family == "CentOS" or ansible_os_family == "Debian"
- name: Set macOS Downloadables
set_fact:
download_files:
- "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-mac-{{ocp_version}}.tar.gz"
- "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-install-mac-{{ocp_version}}.tar.gz"
# - "https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-darwin-amd64.tar.gz"
when: ansible_os_family == "Darwin"
- name: Set Windows Downloadables
set_fact:
download_files:
- "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-windows-{{ocp_version}}.zip"
# - "https://mirror.openshift.com/pub/openshift-v4/clients/odo/latest/odo-windows-amd64.exe.tar.gz"
when: ansible_os_family == "Windows"
- name: Extract OKD tools
command:
argv:
- "{{ansible_env.HOME}}/openshift/bin/oc"
- adm
- release
- extract
- --tools
- --to=/tmp/openshift/okd
- "{{okd_image}}"
- name: Dowload Clients
get_url:
url: "{{item}}"
dest: "/tmp/openshift"
checksum: "sha256:https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/sha256sum.txt"
loop: "{{download_files}}"
- name: Extract Clients
unarchive:
src: "{{item}}"
dest: "{{ocp_bin_dir}}"
mode: 0755
exclude:
- "README.md"
with_fileglob:
- "/tmp/openshift/*.gz"
- name: Extract OKD Clients
unarchive:
src: "{{item}}"
dest: "{{okd_bin_dir}}"
mode: 0755
exclude:
- "README.md"
with_fileglob:
- "/tmp/openshift/okd/*.gz"
- name: Check OCP tools version
command:
argv:
- "{{ocp_bin_dir}}/{{item}}"
- version
with_items:
- oc
- openshift-install
- name: Check OKD tools version
command:
argv:
- "{{okd_bin_dir}}/{{item}}"
- version
with_items:
- oc
- openshift-install
- name: Clear client archives
file:
path: "/tmp/openshift"
state: absent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment