Search code examples
kubernetesansiblek8s-serviceaccount

kubectl Secret - passing service account ( json ) file in ansible k8s module


Am trying to use kubernetes ansible module for creating the kubectl secret, below is my command

kubectl create secret generic -n default test --from-file=gcp=serviceaccount.json

Do we have any way to pass service account json file(--from-file=gcp=serviceaccount.json) in Ansible k8s module,

how to pass this --from-file in the below module?

- name: CREATE SECRET
    k8s:
      state: present
      definition: 
        apiVersion: v1
        kind: Secret
        type: Opaque             
        metadata:
          name: test
          namespace: default     
        data:
         ?? : ??

Solution

  • Am able to resolve the issue with stringData option.

    Ive passed the content of the file with stringData option

    - name: CREATE SECRET
        k8s:
          state: present
          definition: 
            apiVersion: v1
            kind: Secret
            type: Opaque             
            metadata:
              name: test
              namespace: default     
            stringData:
              content of the file