Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added custom context name #315

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions inventory-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
extra_server_args: ""
extra_agent_args: ""

# Optional vars

Check warning on line 22 in inventory-sample.yml

View workflow job for this annotation

GitHub Actions / Lint

yaml[comments-indentation]

Comment not indented like content

Check warning on line 22 in inventory-sample.yml

View workflow job for this annotation

GitHub Actions / Lint

22:3 [comments-indentation] comment not indented like content
# cluster_context: k3s-ansible

Check warning on line 23 in inventory-sample.yml

View workflow job for this annotation

GitHub Actions / Lint

yaml[comments-indentation]

Comment not indented like content

Check warning on line 23 in inventory-sample.yml

View workflow job for this annotation

GitHub Actions / Lint

23:5 [comments-indentation] comment not indented like content
# api_port: 6443
# k3s_server_location: /var/lib/rancher/k3s
# systemd_dir: /etc/systemd/system
Expand All @@ -28,8 +29,8 @@
# List of locally available manifests to apply to the cluster, useful for PVCs or Traefik modifications.
# extra_manifests: [ '/path/to/manifest1.yaml', '/path/to/manifest2.yaml' ]
# airgap_dir: /tmp/k3s-airgap-images
# user_kubectl: true, by default kubectl is symlinked and configured for use by ansible_user. Set to false to only kubectl via root user.

Check warning on line 32 in inventory-sample.yml

View workflow job for this annotation

GitHub Actions / Lint

yaml[line-length]

Line too long (141 > 120 characters)

Check warning on line 32 in inventory-sample.yml

View workflow job for this annotation

GitHub Actions / Lint

32:121 [line-length] line too long (141 > 120 characters)
# server_config_yaml: |
# This is now an inner yaml file. Maintain the indentation.

Check warning on line 34 in inventory-sample.yml

View workflow job for this annotation

GitHub Actions / Lint

yaml[comments-indentation]

Comment not indented like content

Check warning on line 34 in inventory-sample.yml

View workflow job for this annotation

GitHub Actions / Lint

34:7 [comments-indentation] comment not indented like content
# YAML here will be placed as the content of /etc/rancher/k3s/config.yaml
# See https://docs.k3s.io/installation/configuration#configuration-file
1 change: 1 addition & 0 deletions roles/k3s_server/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
k3s_server_location: "/var/lib/rancher/k3s"
systemd_dir: "/etc/systemd/system"

Check warning on line 3 in roles/k3s_server/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use k3s_server_ as a prefix. (vars: systemd_dir)
api_port: 6443

Check warning on line 4 in roles/k3s_server/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use k3s_server_ as a prefix. (vars: api_port)
kubeconfig: ~/.kube/config.new

Check warning on line 5 in roles/k3s_server/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint

var-naming[no-role-prefix]

Variables names from within roles should use k3s_server_ as a prefix. (vars: kubeconfig)
user_kubectl: true
cluster_context: k3s-ansible
6 changes: 3 additions & 3 deletions roles/k3s_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,27 @@

- name: Change server address in kubeconfig on control node
ansible.builtin.shell: |
KUBECONFIG={{ kubeconfig }} kubectl config set-cluster default --server=https://{{ api_endpoint }}:{{ api_port }}

Check warning on line 116 in roles/k3s_server/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

116:121 [line-length] line too long (125 > 120 characters)
delegate_to: 127.0.0.1
become: false
register: csa_result
changed_when:
- csa_result.rc == 0

- name: Setup kubeconfig k3s-ansible context on control node
- name: Setup kubeconfig context on control node - {{ cluster_context }}
when: kubeconfig != "~/.kube/config"
ansible.builtin.replace:
path: "{{ kubeconfig }}"
regexp: 'name: default'
replace: 'name: k3s-ansible'
replace: 'name: {{ cluster_context }}'
delegate_to: 127.0.0.1
become: false

- name: Merge with any existing kubeconfig on control node
when: kubeconfig != "~/.kube/config"
ansible.builtin.shell: |
TFILE=$(mktemp)
KUBECONFIG={{ kubeconfig }} kubectl config set-context k3s-ansible --user=k3s-ansible --cluster=k3s-ansible
KUBECONFIG={{ kubeconfig }} kubectl config set-context {{ cluster_context }} --user={{ cluster_context }} --cluster={{ cluster_context }}

Check warning on line 136 in roles/k3s_server/tasks/main.yml

View workflow job for this annotation

GitHub Actions / Lint

136:121 [line-length] line too long (149 > 120 characters)
KUBECONFIG={{ kubeconfig }} kubectl config view --flatten > ${TFILE}
mv ${TFILE} {{ kubeconfig }}
delegate_to: 127.0.0.1
Expand Down
Loading