Bootstrap FreeKB - OpenShift - List Network using Ansible
OpenShift - List Network using Ansible

Updated:   |  OpenShift articles

This assumes you are already familiar with logging in and logging out of OpenShift using Ansible. If not, check out my article FreeKB - OpenShift - Log into OpenShift using Ansible community.okd.openshift_auth.

Here is an example of how to return the config.openshift.io/v1 network config using Ansible kubernetes.core.k8s_info.

---
- hosts: localhost
  module_defaults:
    group/community.okd.okd:
      host: https://api.op.example.com:6443
      validate_certs: False
  tasks:
  - block:

    - name: login
      community.okd.openshift_auth:
        username: john.doe
        password: itsasecret
      register: openshift_auth_results

    - name: store config.openshift.io/v1 cluster network in a dictionary named 'network_config'
      kubernetes.core.k8s_info:
        api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
        api_version: config.openshift.io/v1
        kind: Network
        name: cluster
      register: network_config

    - ansible.builtin.debug:
        var: network_config

    - name: set_fact network_type (OpenShiftSDN or OVNKubernetes)
      ansible.builtin.set_fact:
        network_type: "{{ item.spec.networkType }}"
      with_items: "{{ network_config.resources }}"
      loop_control:
        label: "{{ item.spec.networkType }}"

    always:

    - name: logout
      community.okd.openshift_auth:
        state: absent
        api_key: "{{ openshift_auth_results.openshift_auth.api_key }}"
...

 

 


 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter f5207c in the box below so that we can be sure you are a human.