### Install collection_prep Package Source: https://github.com/ansible-collections/kubernetes.core/blob/main/CONTRIBUTING.md Install the collection_prep package to manage and update module documentation. Clone the repository and install using pip. ```bash # git clone https://github.com/ansible-network/collection_prep # cd collection_prep # pip install . ``` -------------------------------- ### Run Command in Pod with Inventory Variables Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.kubectl_connection.rst This example demonstrates running a command in a pod using inventory variables to define connection details, including the kubeconfig path, pod name, container, and namespace. Python must be installed in the pod's image. ```yaml - name: Run a command in a pod using local kubectl with inventory variables # Example inventory: # k8s: # hosts: # foo.example.com: # ansible_connection: kubernetes.core.kubectl # ansible_kubectl_kubeconfig: /root/.kube/foo.example.com.config # ansible_kubectl_pod: my-foo-pod # ansible_kubectl_container: my-foo-container # ansible_kubectl_namespace: my-foo-namespace # bar.example.com: # ansible_connection: kubernetes.core.kubectl # ansible_kubectl_kubeconfig: /root/.kube/bar.example.com.config # ansible_kubectl_pod: my-bar-pod # ansible_kubectl_container: my-bar-container # ansible_kubectl_namespace: my-bar-namespace hosts: k8s gather_facts: no tasks: # be aware that the command is executed as the user that started the container # and requires python to be installed in the image - name: Run a command in a pod ansible.builtin.command: echo "Hello, World!" ``` -------------------------------- ### Install Kubernetes Python Library Source: https://github.com/ansible-collections/kubernetes.core/blob/main/README.md Install the necessary Python client library for the Kubernetes collection to interact with Kubernetes APIs. Use pip3 for installation. ```bash pip3 install kubernetes ``` -------------------------------- ### Gather Helm Plugin Info Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_plugin_info_module.rst This example demonstrates how to gather information about all Helm plugins. ```APIDOC ## Gather Helm Plugin Info ### Description Gather information about Helm plugins. ### Method Uses the `helm_plugin_info` module. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```yaml - name: Gather Helm plugin info kubernetes.core.helm_plugin_info: ``` ### Response #### Success Response (200) - **command** (string) - Full `helm` command built by this module. - **plugin_list** (list) - Helm plugin dict inside a list. #### Response Example ```json { "command": "helm plugin list ...", "plugin_list": [ { "name": "example-plugin", "version": "1.0.0", "location": "/path/to/plugin" } ] } ``` ``` -------------------------------- ### Install Helm Plugin from URL Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_plugin_module.rst Use this snippet to install a Helm plugin from a remote URL. Ensure the URL points to a valid plugin archive. ```yaml - name: Install Helm env plugin kubernetes.core.helm_plugin: plugin_path: https://github.com/adamreese/helm-env state: present ``` ```yaml - name: Install Helm plugin from local filesystem kubernetes.core.helm_plugin: plugin_path: https://domain/path/to/plugin.tar.gz state: present ``` -------------------------------- ### Gather Specific Helm Plugin Info Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_plugin_info_module.rst This example shows how to gather information for a specific Helm plugin by its name. ```APIDOC ## Gather Specific Helm Plugin Info ### Description Gather information about a specific Helm plugin by its name. ### Method Uses the `helm_plugin_info` module with the `plugin_name` parameter. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```yaml - name: Gather Helm env plugin info kubernetes.core.helm_plugin_info: plugin_name: env ``` ### Response #### Success Response (200) - **command** (string) - Full `helm` command built by this module. - **plugin_list** (list) - Helm plugin dict inside a list. #### Response Example ```json { "command": "helm plugin list --filter env ...", "plugin_list": [ { "name": "env", "version": "1.2.3", "location": "/path/to/env/plugin" } ] } ``` ``` -------------------------------- ### Create a Kubernetes Service using inline spec Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_service_module.rst This example shows how to create a Kubernetes Service by providing the full spec inline. ```APIDOC ## create a Kubernetes Service using inline spec ### Description This module allows users to create, update, and delete Kubernetes Service objects by providing the full specification inline. ### Parameters #### Path Parameters - **state** (str) - Required - Whether the Service should exist or not. - **name** (str) - Required - Name of the Service. - **namespace** (str) - Optional - Namespace to create the Service in. - **inline** (dict) - Required - The Service specification. - **spec** (dict) - Required - The Service specification. - **ports** (list) - Required - List of ports to expose. - **port** (int) - Required - The port number. - **protocol** (str) - Optional - The protocol for the port (TCP, UDP, SCTP). - **selector** (dict) - Required - Labels to select pods for the Service. ### Request Example ```yaml - name: Expose https port with ClusterIP using spec kubernetes.core.k8s_service: state: present name: test-https namespace: default inline: spec: ports: - port: 443 protocol: TCP selector: key: special ``` ### Response #### Success Response (200) - **result** (complex) - The created, patched, or otherwise present Service object. - **api_version** (string) - The versioned schema of this representation of an object. - **kind** (string) - Always 'Service'. - **metadata** (complex) - Data that helps uniquely identify an object, including a name, description, tags, and labels. ``` -------------------------------- ### Manually Start Turbo Mode Server Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/ansible_turbo_mode.rst Use this command to manually start the Turbo Mode server. Ensure the PYTHONPATH is set correctly and specify the desired socket path. ```shell PYTHONPATH=$HOME/.ansible/collections python -m ansible_collections.cloud.common.plugins.module_utils.turbo.server --socket-path $HOME/.ansible/tmp/turbo_mode.kubernetes.core.socket ``` -------------------------------- ### Get Cluster Information Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_cluster_info_module.rst This example demonstrates how to retrieve general cluster information using the k8s_cluster_info module. ```APIDOC ## Get Cluster information ### Description Retrieves information about the Kubernetes cluster, including available APIs and resources. ### Module kubernetes.core.k8s_cluster_info ### Parameters This module does not take any parameters for basic usage. ### Return Values - **apis** (dictionary) - A dictionary of group and version of resources found in the cluster. - **categories** (list) - A list of API categories. - **name** (string) - The short name of the resource. - **namespaced** (boolean) - Indicates if the resource is namespaced. - **preferred** (boolean) - Indicates if the resource version is preferred. - **short_names** (string) - A list of short names for the resource. ``` -------------------------------- ### Create a Kubernetes Service Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_service_module.rst This example demonstrates how to create a Kubernetes Service of type ClusterIP to expose an application on port 443. ```APIDOC ## create a Kubernetes Service ### Description This module allows users to create, update, and delete Kubernetes Service objects. ### Parameters #### Path Parameters - **state** (str) - Required - Whether the Service should exist or not. - **name** (str) - Required - Name of the Service. - **namespace** (str) - Optional - Namespace to create the Service in. - **ports** (list) - Required - List of ports to expose. - **port** (int) - Required - The port number. - **protocol** (str) - Optional - The protocol for the port (TCP, UDP, SCTP). - **selector** (dict) - Required - Labels to select pods for the Service. ### Request Example ```yaml - name: Expose https port with ClusterIP kubernetes.core.k8s_service: state: present name: test-https namespace: default ports: - port: 443 protocol: TCP selector: key: special ``` ### Response #### Success Response (200) - **result** (complex) - The created, patched, or otherwise present Service object. - **api_version** (string) - The versioned schema of this representation of an object. - **kind** (string) - Always 'Service'. - **metadata** (complex) - Data that helps uniquely identify an object, including a name, description, tags, and labels. ``` -------------------------------- ### Get a log from a DeploymentConfig using k8s_log Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_log_module.rst Fetch logs from a pod managed by an OpenShift DeploymentConfig. This example includes the API version, kind, namespace, name, and uses tail_lines to limit the output to the last 100 lines. ```yaml - name: Get a log from a DeploymentConfig kubernetes.core.k8s_log: api_version: apps.openshift.io/v1 kind: DeploymentConfig namespace: testing name: example tail_lines: 100 register: log ``` -------------------------------- ### Install kubernetes.core Collection Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/docsite/rst/kubernetes_scenarios/k8s_intro.rst Install the Kubernetes Ansible collection using ansible-galaxy. This collection provides modules and plugins for Kubernetes orchestration. ```bash $ ansible-galaxy collection install kubernetes.core ``` -------------------------------- ### Execute a command in a Kubernetes pod Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_exec_module.rst This example demonstrates how to execute a command within a specified pod and namespace. The output of the command is registered for further inspection. ```APIDOC ## kubernetes.core.k8s_exec ### Description Executes a command inside a container of a pod. ### Parameters #### Path Parameters - **namespace** (str) - Namespace of the pod - **pod** (str) - Pod name where the command will be executed - **container** (str) - Container name where the command will be executed - **command** (str) - The command to execute in the pod ### Request Example ```yaml - name: Execute a command kubernetes.core.k8s_exec: namespace: myproject pod: zuul-scheduler command: zuul-scheduler full-reconfigure ``` ### Return Values #### Success Response - **result** (complex) - The command object - **rc** (integer) - The command status code (added in 2.2.0) - **return_code** (integer) - The command status code (added in 1.0.0) ``` -------------------------------- ### Specify container name Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_exec_module.rst This example demonstrates how to execute a command within a specific container when a pod has multiple containers. ```APIDOC ## kubernetes.core.k8s_exec (specify container) ### Description Executes a command inside a specific container of a pod. ### Parameters #### Path Parameters - **namespace** (str) - Namespace of the pod - **pod** (str) - Pod name where the command will be executed - **container** (str) - Container name where the command will be executed - **command** (str) - The command to execute in the pod ### Request Example ```yaml - name: Specify a container name to execute the command on kubernetes.core.k8s_exec: namespace: myproject pod: busybox-test container: manager command: echo "hello" ``` ### Return Values #### Success Response - **result** (complex) - The command object - **rc** (integer) - The command status code (added in 2.2.0) - **return_code** (integer) - The command status code (added in 1.0.0) ``` -------------------------------- ### Install Helm Plugin with Specific Version Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_plugin_module.rst Install a Helm plugin from a specified URL, targeting a particular version. This is useful for ensuring compatibility or using specific features. ```yaml - name: Install Helm plugin with a specific version kubernetes.core.helm_plugin: plugin_version: 2.0.1 plugin_path: https://domain/path/to/plugin.tar.gz state: present ``` -------------------------------- ### Install Kubernetes Core Collection Source: https://github.com/ansible-collections/kubernetes.core/blob/main/README.md Install the collection using the Ansible Galaxy CLI. This command ensures the collection is available for use in your Ansible projects. ```bash ansible-galaxy collection install kubernetes.core ``` -------------------------------- ### Login to remote registry Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_registry_auth_module.rst Example of how to log in to a remote Helm registry using provided credentials. ```APIDOC ## kubernetes.core.helm_registry_auth ### Description Logs in or out of a remote registry server. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **username** (string) - Username for the registry. aliases: repo_username - **password** (string) - Password for the registry. aliases: repo_password - **host** (string) - The Helm registry server URL. - **state** (string) - Desired state of the registry. Choices: present, absent. Default: present. - **plain_http** (boolean) - Use insecure HTTP connections for `helm registry login`. Requires Helm >= 3.18.0. Choices: no, yes. Default: no. - **client_cert** (string) - Path to the client certificate SSL file to use when using TLS client authentication. - **client_key** (string) - Path to the client key SSL file for identify registry client using this key file. ### Request Example ```yaml - name: Login to remote registry kubernetes.core.helm_registry_auth: username: admin password: "sample_password" host: localhost:5000 ``` ### Response #### Success Response (200) - **command** (string) - The helm command that was executed. ``` -------------------------------- ### Managing Kubernetes Taints Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_taint_module.rst This example demonstrates how to use the k8s_taint module to ensure a specific taint is absent from a Kubernetes node. ```APIDOC ## k8s_taint ### Description Manages taints on Kubernetes nodes. This module can be used to add or remove taints from nodes. ### Parameters - **state** (str) - Required - The desired state for the taint. Use 'present' to add a taint or 'absent' to remove one. - **name** (str) - Required - The name of the node to manage taints for. - **taints** (list) - Optional - A list of taints to apply or remove. Each taint is a dictionary with 'effect', 'key', and 'value' fields. #### Example (Removing a taint) ```yaml - name: Ensure a specific taint is absent from a node kubernetes.core.k8s_taint: state: absent name: foo taints: - effect: NoExecute key: "key1" value: "value1" ``` ### Return Values - **result** (complex) - The tainted Node object. Will be empty in the case of a deletion. - **api_version** (string) - The versioned schema of this representation of an object. - **kind** (string) - Represents the REST resource this object represents. - **metadata** (complex) - Standard object metadata. Includes name, namespace, annotations, labels, etc. - **spec** (complex) - Specific attributes of the object. Will vary based on the `api_version` and `kind`. - **status** (complex) - Current status details for the object. ``` -------------------------------- ### Check command return code Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_exec_module.rst This example shows how to execute a command that might fail and then check its return code (rc) to determine success or failure. ```APIDOC ## kubernetes.core.k8s_exec (with return code check) ### Description Executes a command inside a container of a pod and registers the return code. ### Parameters #### Path Parameters - **namespace** (str) - Namespace of the pod - **pod** (str) - Pod name where the command will be executed - **container** (str) - Container name where the command will be executed - **command** (str) - The command to execute in the pod ### Request Example ```yaml - name: Check RC status of command executed kubernetes.core.k8s_exec: namespace: myproject pod: busybox-test command: cmd_with_non_zero_exit_code register: command_status ignore_errors: True - name: Check last command status debug: msg: "cmd failed" when: command_status.rc != 0 ``` ### Return Values #### Success Response - **result** (complex) - The command object - **rc** (integer) - The command status code (added in 2.2.0) - **return_code** (integer) - The command status code (added in 1.0.0) ``` -------------------------------- ### Create Pod using k8s module Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_module.rst Example of creating a Kubernetes Pod using the k8s module with a defined spec. Ensure the `generate_name` is set for unique naming. ```yaml - name: Create pod kubernetes.core.k8s: namespace: testing definition: apiVersion: v1 kind: Pod metadata: generate_name: pod- spec: containers: - name: py image: python:3.7-alpine imagePullPolicy: IfNotPresent ``` -------------------------------- ### Manage Kubernetes Service with FQCN Source: https://github.com/ansible-collections/kubernetes.core/blob/main/README.md Define and manage a Kubernetes Service using the FQCN. This example creates a LoadBalancer Service named 'myapp' in the 'myapp' namespace. ```yaml --- - hosts: localhost gather_facts: false connection: local tasks: - name: Ensure the myapp Service exists in the myapp Namespace. kubernetes.core.k8s: state: present definition: apiVersion: v1 kind: Service metadata: name: myapp namespace: myapp spec: type: LoadBalancer ports: - port: 8080 targetPort: 8080 selector: app: myapp ``` -------------------------------- ### Manage Kubernetes Namespace with FQCN Source: https://github.com/ansible-collections/kubernetes.core/blob/main/README.md Use the Fully Qualified Collection Namespace (FQCN) to manage Kubernetes resources. This example ensures a Namespace named 'myapp' exists. ```yaml --- - hosts: localhost gather_facts: false connection: local tasks: - name: Ensure the myapp Namespace exists. kubernetes.core.k8s: api_version: v1 kind: Namespace name: myapp state: present ``` -------------------------------- ### Copy Local Directory to Remote Pod Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_cp_module.rst This example demonstrates copying a local directory to a remote pod. The 'tar' binary must be present in the container for this operation. ```yaml - name: Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod kubernetes.core.k8s_cp: namespace: some-namespace pod: some-pod remote_path: /tmp/bar_dir local_path: /tmp/foo_dir ``` -------------------------------- ### Get the logs from all containers in a pod using k8s_log Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_log_module.rst This example shows how to retrieve logs from all containers within a specified pod. Set `all_containers` to `true` to enable this functionality. ```yaml - name: Get the logs from all containers in pod kubernetes.core.k8s_log: namespace: testing name: some-pod all_containers: true ``` -------------------------------- ### Get Cluster Information Without Cache Invalidation Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_cluster_info_module.rst This example demonstrates how to retrieve cluster information without invalidating the module's internal cache. Use this when you want to avoid unnecessary cache refreshes. ```yaml - name: Do not invalidate cache before getting information kubernetes.core.k8s_cluster_info: invalidate_cache: False register: api_status ``` -------------------------------- ### Run Molecule Tests with KinD Source: https://github.com/ansible-collections/kubernetes.core/blob/main/README.md Set up a local Kubernetes cluster using KinD and run the Molecule integration tests. ```bash kind create cluster make test-molecule ``` -------------------------------- ### Execute a command in a pod Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_exec_module.rst This example demonstrates how to execute a simple command within a specified pod and namespace. Ensure the authenticated user has the necessary read/write permissions for pods and pods/exec resources. ```yaml - name: Execute a command kubernetes.core.k8s_exec: namespace: myproject pod: zuul-scheduler command: zuul-scheduler full-reconfigure ``` -------------------------------- ### Install cloud.common Collection Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/ansible_turbo_mode.rst Install the cloud.common collection using ansible-galaxy to meet the requirements for Ansible Turbo mode. ```bash ansible-galaxy collection install cloud.common ``` -------------------------------- ### Fetch all deployments Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_lookup.rst Retrieve all Deployment resources by specifying 'kind' as 'Deployment'. ```yaml - name: Fetch all deployments set_fact: deployments: "{{ query('kubernetes.core.k8s', kind='Deployment') }}" ``` -------------------------------- ### Create a Deployment from a Local File Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_module.rst Creates a Kubernetes Deployment by reading its definition from a local YAML file. The `src` parameter points to the file path. ```yaml - name: Create a Deployment by reading the definition from a local file kubernetes.core.k8s: state: present src: /testing/deployment.yml ``` -------------------------------- ### Create a Deployment from a Template File Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_module.rst Creates a Kubernetes Deployment using a Jinja2 template file. The template is rendered before being applied to the cluster. ```yaml - name: Read definition template file from the Ansible controller file system kubernetes.core.k8s: state: present template: '/testing/deployment.j2' ``` -------------------------------- ### Wait for OpenShift bootstrap to complete using k8s_info Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_info_module.rst This example demonstrates how to use k8s_info to check for the completion of an OpenShift bootstrap process by monitoring a ConfigMap. It registers the status and uses `until` to wait for specific conditions to be met. ```yaml - name: Wait for OpenShift bootstrap to complete kubernetes.core.k8s_info: api_version: v1 kind: ConfigMap name: bootstrap namespace: kube-system register: ocp_bootstrap_status until: > ocp_bootstrap_status.resources is defined and (ocp_bootstrap_status.resources | length > 0) and (ocp_bootstrap_status.resources[0].data.status is defined) and (ocp_bootstrap_status.resources[0].data.status == 'complete') retries: 60 delay: 15 ``` -------------------------------- ### Logout from remote registry Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_registry_auth_module.rst Example of how to log out from a remote Helm registry. ```APIDOC ## kubernetes.core.helm_registry_auth ### Description Logs in or out of a remote registry server. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **username** (string) - Username for the registry. aliases: repo_username - **password** (string) - Password for the registry. aliases: repo_password - **host** (string) - The Helm registry server URL. - **state** (string) - Desired state of the registry. Choices: present, absent. Default: present. - **plain_http** (boolean) - Use insecure HTTP connections for `helm registry login`. Requires Helm >= 3.18.0. Choices: no, yes. Default: no. - **client_cert** (string) - Path to the client certificate SSL file to use when using TLS client authentication. - **client_key** (string) - Path to the client key SSL file for identify registry client using this key file. ### Request Example ```yaml - name: Logout from remote registry kubernetes.core.helm_registry_auth: state: absent host: localhost:5000 ``` ### Response #### Success Response (200) - **command** (string) - The helm command that was executed. ``` -------------------------------- ### Run Kustomize Lookup Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.kustomize_lookup.rst Use the kustomize lookup plugin to generate Kubernetes resources. Specify the binary path if kustomize or kubectl is not in the system's PATH. ```yaml - name: Run lookup using kustomize ansible.builtin.set_fact: resources: "{{ lookup('kubernetes.core.kustomize', binary_path='/path/to/kustomize') }}" ``` ```yaml - name: Run lookup using kubectl kustomize ansible.builtin.set_fact: resources: "{{ lookup('kubernetes.core.kustomize', binary_path='/path/to/kubectl') }}" ``` -------------------------------- ### Get a list of all pods from any namespace Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_info_module.rst Retrieves all Pod objects across all namespaces in the cluster. ```yaml - name: Get a list of all pods from any namespace kubernetes.core.k8s_info: kind: Pod register: pod_list ``` -------------------------------- ### Gather Helm Release Information Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_info_module.rst This example demonstrates how to gather information about a specific Helm chart release within a given namespace. It also shows how to filter releases based on their state. ```APIDOC ## kubernetes.core.helm_info ### Description Gather information of Helm chart releases. ### Parameters #### Path Parameters None #### Query Parameters - **name** (str) - Required - The name of the Helm release. - **release_namespace** (str) - Required - The namespace where the Helm release is deployed. - **release_state** (list) - Optional - A list of release states to filter by. Possible values include 'deployed', 'uninstalled', 'superseded', 'failed', 'uninstalling', 'pending-install', 'pending-upgrade', 'pending-rollback'. - **validate_certs** (bool) - Optional - Whether or not to verify the API server's SSL certificates. Defaults to 'yes'. ### Request Example ```yaml - name: Gather information of Grafana chart inside monitoring namespace kubernetes.core.helm_info: name: test release_namespace: monitoring - name: Gather information about test-chart with pending state kubernetes.core.helm_info: name: test-chart release_namespace: testenv release_state: - pending ``` ### Response #### Success Response (200) - **status** (complex) - A dictionary of status output. Returned only when the release exists. - **app_version** (string) - Version of the app deployed. Returned always. - **chart** (string) - Chart name and chart version. Returned always. - **hooks** (list) - List of hooks associated with the release. Returned always. #### Response Example ```json { "status": { "app_version": "1.16.0", "chart": "grafana-6.10.4", "hooks": [], "name": "test", "namespace": "monitoring", "revision": "1", "updated": "2023-10-27 10:00:00", "status": "deployed" } } ``` ``` -------------------------------- ### Get a list of all service objects Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_info_module.rst Fetches all Service objects within a specified namespace. ```yaml - name: Get a list of all service objects kubernetes.core.k8s_info: api_version: v1 kind: Service namespace: testing register: service_list ``` -------------------------------- ### Get an existing Service object Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_info_module.rst Retrieves a specific Service object by its name and namespace. ```yaml - name: Get an existing Service object kubernetes.core.k8s_info: api_version: v1 kind: Service name: web namespace: testing register: web_service ``` -------------------------------- ### Render Helm Templates and Register Output Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_template_module.rst This example demonstrates rendering Helm chart templates and capturing the rendered output in a variable. The output can then be used for further processing, such as writing to a file. ```yaml - name: Render templates kubernetes.core.helm_template: chart_ref: stable/prometheus register: result - name: Write templates to file copy: dest: myfile.yaml content: "{{ result.stdout }}" ``` -------------------------------- ### Control Cache Invalidation Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_cluster_info_module.rst This example shows how to prevent the module from invalidating its cache before fetching information. ```APIDOC ## Do not invalidate cache before getting information ### Description Retrieves cluster information without invalidating the module's cache. This can be useful for performance optimization if the cluster state is not expected to change frequently between calls. ### Module kubernetes.core.k8s_cluster_info ### Parameters - **invalidate_cache** (boolean) - Optional. If set to False, the module will not invalidate its cache before fetching information. Defaults to True. ### Return Values - **apis** (dictionary) - A dictionary of group and version of resources found in the cluster. - **categories** (list) - A list of API categories. - **name** (string) - The short name of the resource. - **namespaced** (boolean) - Indicates if the resource is namespaced. - **preferred** (boolean) - Indicates if the resource version is preferred. - **short_names** (string) - A list of short names for the resource. ``` -------------------------------- ### Create a Deployment from a Template with Custom Delimiters Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_module.rst Applies a Kubernetes Deployment using a Jinja2 template file, specifying custom variable start and end strings for template rendering. ```yaml - name: Read definition template file from the Ansible controller file system that uses custom start/end strings kubernetes.core.k8s: state: present template: path: '/testing/deployment.j2' variable_start_string: '[[' variable_end_string: ']]' ``` -------------------------------- ### kubernetes.core.helm_info Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.helm_info_module.rst Get information (values, states, ...) from Helm package deployed inside the cluster. ```APIDOC ## kubernetes.core.helm_info ### Description Get information (values, states, ...) from Helm package deployed inside the cluster. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Run Collection Unit Tests Source: https://github.com/ansible-collections/kubernetes.core/blob/main/README.md Execute the collection's unit test suite using the provided make command. ```bash make test-unit ``` -------------------------------- ### Get a log from a Pod using k8s_log Source: https://github.com/ansible-collections/kubernetes.core/blob/main/docs/kubernetes.core.k8s_log_module.rst Use this snippet to retrieve logs from a specific pod by its name and namespace. ```yaml - name: Get a log from a Pod kubernetes.core.k8s_log: name: example-1 namespace: testing register: log ```