k3s.yml can be broken by running the playbook several times
Example job: https://open.greenhost.net/openappstack/openappstack/-/jobs/134713
By re-running the ansible playbook, we ended up with the error Error in configuration: context was not found for specified context: default
This is because these jobs don't end up with the same result when re-run:
- name: Replace clustername in kubeconfig context section
tags:
- k3s
- kubeconfig
lineinfile:
dest: "/etc/rancher/k3s/k3s.yaml"
state: present
regexp: "^ cluster: default"
line: " cluster: {{ inventory_hostname }}"
- name: Replace clustername in kubeconfig cluster section
tags:
- k3s
- kubeconfig
lineinfile:
dest: "/etc/rancher/k3s/k3s.yaml"
state: present
regexp: "^ name: default"
line: " name: {{ inventory_hostname }}"
insertbefore: "contexts:"
firstmatch: true
We should use something that understand yaml to make sure we don't break it. Weirdly enough Ansible doesn't have a yaml
module, but a yq
command could work.