OpenShift - List Network using Ansible

by
Jeremy Canfield |
Updated: July 09 2025
| 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