Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a Kubernetes Secret with Ansible?

I'm using an Ansible JMeter Operator to do distributed load testing and am having trouble with creating a Kubernetes secret. The operator I'm modifying is the JMeter one and the additional YAML I'm adding is as below:

- name: InfluxDB Storage Secret
  k8s:
    apiVersion: v1
    kind: Secret
    type: Opaque
    metadata:
      name: azure-storage-account-infxluxdb-secret
      namespace: '{{ meta.namespace }}'
    stringData:
      azurestorageaccountname: 'xxxxxxx'
      azurestorageaccountkey: 'xxxxxxxxxxx'

Is there anything wrong with the YAML definition? I'm modifying the roles/jmeter/tasks/main.yaml of the role to add it into my specific namespace.

like image 296
David C Avatar asked Dec 05 '19 21:12

David C


People also ask

Can Ansible manage Kubernetes?

With the Ansible Kubernetes module, you get a quick way to effectively work with Kubernetes objects within the cluster on remote hosts. Now, you can automate containerized application management with the Ansible Kubernetes module.

Does Ansible support Kubernetes?

To manage the lifecycle of your application on Kubernetes using Ansible, you can use the Kubernetes Collection for Ansible. This collection of Ansible modules allows a developer to either leverage their existing Kubernetes resource files written in YAML or express the lifecycle management in native Ansible.


1 Answers

Here is my example, that works for me, hope it help.

  - name: CREATE MONGOSECRETS SECRET
    kubernetes.core.k8s:
      state: present
      definition: 
        apiVersion: v1
        kind: Secret
        type: Opaque             
        metadata:
          name: "{{ secret_name }}"
          namespace: "{{ project_name | lower }}"     
        data:
          config_data.json: "{{ lookup('template', mongo_conn_templates_path + '/config_data.json' ) | tojson | b64encode }}"
like image 132
Samush Avatar answered Oct 19 '22 02:10

Samush