Skip to Content
Practical Ansible 2
book

Practical Ansible 2

by Daniel Oh, James Freeman, Fabio Alessandro Locati
June 2020
Intermediate to advanced content levelIntermediate to advanced
410 pages
9h 52m
English
Packt Publishing
Content preview from Practical Ansible 2

Listing Kubernetes namespaces with Ansible

A Kubernetes cluster has multiple namespaces internally, and you can usually find the ones a cluster has with kubectl get namespaces. You can do the same with Ansible by creating a file called k8s-ns-show.yaml with the following content:

---- hosts: localhost  tasks:    - name: Get information from K8s      k8s_info:        api_version: v1        kind: Namespace      register: ns    - name: Print info      debug:        var: ns

We can now execute this, as follows:

$ ansible-playbook k8s-ns-show.yaml

You will now see information regarding the namespaces in the output.

Notice that in the seventh line of the code (kind: Namespace), we are specifying the type of resources we are interested in. You can specify other Kubernetes object types to ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Ansible - Third Edition

Mastering Ansible - Third Edition

James Freeman, Jesse Keating
Security Automation with Ansible 2

Security Automation with Ansible 2

Akash Mahajan, MADHU AKULA

Publisher Resources

ISBN: 9781789807462Supplemental Content