mirror of
https://github.com/k3s-io/k3s-ansible.git
synced 2024-09-24 03:22:43 +02:00
Completely setup kubectl for ansible_user, with option to disable it
Signed-off-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
parent
1527df5631
commit
4eee09092a
@ -28,6 +28,7 @@ k3s_cluster:
|
|||||||
# List of locally available manifests to apply to the cluster, useful for PVCs or Traefik modifications.
|
# 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' ]
|
# extra_manifests: [ '/path/to/manifest1.yaml', '/path/to/manifest2.yaml' ]
|
||||||
# airgap_dir: /tmp/k3s-airgap-images
|
# 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.
|
||||||
# server_config_yaml: |
|
# server_config_yaml: |
|
||||||
# This is now an inner yaml file. Maintain the indentation.
|
# This is now an inner yaml file. Maintain the indentation.
|
||||||
# YAML here will be placed as the content of /etc/rancher/k3s/config.yaml
|
# YAML here will be placed as the content of /etc/rancher/k3s/config.yaml
|
||||||
|
@ -3,3 +3,4 @@ k3s_server_location: "/var/lib/rancher/k3s"
|
|||||||
systemd_dir: "/etc/systemd/system"
|
systemd_dir: "/etc/systemd/system"
|
||||||
api_port: 6443
|
api_port: 6443
|
||||||
kubeconfig: ~/.kube/config.new
|
kubeconfig: ~/.kube/config.new
|
||||||
|
user_kubectl: true
|
||||||
|
@ -68,26 +68,11 @@
|
|||||||
state: started
|
state: started
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
- name: Create directory .kube
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: ~{{ ansible_user }}/.kube
|
|
||||||
state: directory
|
|
||||||
owner: "{{ ansible_user }}"
|
|
||||||
mode: "u=rwx,g=rx,o="
|
|
||||||
|
|
||||||
- name: Pause to allow first server startup
|
- name: Pause to allow first server startup
|
||||||
when: (groups['server'] | length) > 1
|
when: (groups['server'] | length) > 1
|
||||||
ansible.builtin.pause:
|
ansible.builtin.pause:
|
||||||
seconds: 10
|
seconds: 10
|
||||||
|
|
||||||
- name: Copy config file to user home directory
|
|
||||||
ansible.builtin.copy:
|
|
||||||
src: /etc/rancher/k3s/k3s.yaml
|
|
||||||
dest: ~{{ ansible_user }}/.kube/config
|
|
||||||
remote_src: true
|
|
||||||
owner: "{{ ansible_user }}"
|
|
||||||
mode: "u=rw,g=,o="
|
|
||||||
|
|
||||||
- name: Add K3s autocomplete to user bashrc
|
- name: Add K3s autocomplete to user bashrc
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: "~{{ ansible_user }}/.bashrc"
|
path: "~{{ ansible_user }}/.bashrc"
|
||||||
@ -103,7 +88,7 @@
|
|||||||
|
|
||||||
- name: Copy kubectl config to local machine
|
- name: Copy kubectl config to local machine
|
||||||
ansible.builtin.fetch:
|
ansible.builtin.fetch:
|
||||||
src: ~{{ ansible_user }}/.kube/config
|
src: /etc/rancher/k3s/k3s.yaml
|
||||||
dest: "{{ kubeconfig }}"
|
dest: "{{ kubeconfig }}"
|
||||||
flat: true
|
flat: true
|
||||||
|
|
||||||
@ -171,11 +156,41 @@
|
|||||||
delay: 10
|
delay: 10
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Create symlinks
|
- name: Setup kubectl for user
|
||||||
|
when: user_kubectl
|
||||||
|
block:
|
||||||
|
|
||||||
|
- name: Create kubectl symlink
|
||||||
|
when: lookup('fileglob', '/usr/local/bin/kubectl', errors='warn') | length == 0
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
src: /usr/local/bin/k3s
|
src: /usr/local/bin/k3s
|
||||||
dest: /usr/local/bin/{{ item }}
|
dest: /usr/local/bin/kubectl
|
||||||
state: link
|
state: link
|
||||||
with_items:
|
|
||||||
- kubectl
|
- name: Create directory .kube
|
||||||
- crictl
|
ansible.builtin.file:
|
||||||
|
path: ~{{ ansible_user }}/.kube
|
||||||
|
state: directory
|
||||||
|
owner: "{{ ansible_user }}"
|
||||||
|
mode: "u=rwx,g=rx,o="
|
||||||
|
|
||||||
|
- name: Copy config file to user home directory
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: /etc/rancher/k3s/k3s.yaml
|
||||||
|
dest: ~{{ ansible_user }}/.kube/config
|
||||||
|
remote_src: true
|
||||||
|
owner: "{{ ansible_user }}"
|
||||||
|
mode: "u=rw,g=,o="
|
||||||
|
|
||||||
|
- name: Configure default KUBECONFIG for user
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: ~{{ ansible_user }}/.bashrc
|
||||||
|
regexp: 'export KUBECONFIG=~/.kube/config'
|
||||||
|
line: 'export KUBECONFIG=~/.kube/config # Added by k3s-ansible'
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Configure kubectl autocomplete
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: ~{{ ansible_user }}/.bashrc
|
||||||
|
regexp: '\.\s+<\(kubectl completion bash\)'
|
||||||
|
line: ". <(kubectl completion bash) # Added by k3s-ansible"
|
||||||
|
Loading…
Reference in New Issue
Block a user