I am learning Ansible & dealing with Kubernetes clusters. I would like to have an Ansible task which can change the value in .kube/config
in my local Ansible host. For example, the .kube/config
content looks like this:
apiVersion: v1
clusters:
- cluster:
server: xxx
name: xxx
contexts:
- context:
cluster: yyy
user: yyy
name: yyy
users:
- name: xxx
user: xxx
I basically would like to have an Ansible task to be able to do the following things:
change those values of
xxx
,yyy
in the file.kube/config
on ansible host.append new content under each section of
clusters
,context
&users
if the values do not exist.
Is there a Kubernetes module or plugin I could directly use to achieve it? If not, could someone guide me how to achieve it?
==== I tried this ====
I tried :
- name: Update value to foo
replace:
path: ~/.kube/config
regexp: 'yyy'
regexp: 'foo'
delegate_to: localhost
When running the task, the file content doesn't change at all. Why? (Task has been executed based on logs)