Skip to content

Instantly share code, notes, and snippets.

@tommeramber
Created June 11, 2025 09:46
Show Gist options
  • Save tommeramber/769283ae607e06be88bd849022cc96e2 to your computer and use it in GitHub Desktop.
Save tommeramber/769283ae607e06be88bd849022cc96e2 to your computer and use it in GitHub Desktop.
---
- name: ocp test
hosts: localhost #A must because the invenroty is empty
gather_facts: false
pre_tasks:
#OCP login based on input
- name: set oc login command based on input from user
set_fact:
oc_login: >-
{% if env == "nocp" %}
oc login --server={{ lookup(’env’, ’NOCP_AUTH_API’) }} --token={{ lookup(’env’, ’NOCP_AUTH_TOKEN’) }} --insecure-skip-tls-verify=true
{% elif env == "pocp" %}
oc login --server={{ lookup(’env’, ’POCP_AUTH_API’) }} --token={{ lookup(’env’, ’POCP_AUTH_TOKEN’) }} --insecure-skip-tls-verify=true
{% else %}
INVALID
{% endif %}
- name: Fail if no valid ocp is being specificed
fail:
msg: "Invalid var value env: ’{{ env }}’"
when: oc_login == "INVALID"
- name: Execute oc login based on user input
shell: "{{ oc_login }}"
when: oc_login.strip() != "INVALID"
tasks:
- name: oc whoami
shell: "oc whoami --show-console"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment