mirror of
https://github.com/k3s-io/k3s-ansible.git
synced 2025-12-25 00:12:37 +01:00
Completely setup kubectl for ansible_user, with option to disable it (#278)
Signed-off-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
@@ -3,3 +3,4 @@ k3s_server_location: "/var/lib/rancher/k3s"
|
||||
systemd_dir: "/etc/systemd/system"
|
||||
api_port: 6443
|
||||
kubeconfig: ~/.kube/config.new
|
||||
user_kubectl: true
|
||||
|
||||
@@ -68,26 +68,11 @@
|
||||
state: started
|
||||
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
|
||||
when: (groups['server'] | length) > 1
|
||||
ansible.builtin.pause:
|
||||
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
|
||||
ansible.builtin.lineinfile:
|
||||
path: "~{{ ansible_user }}/.bashrc"
|
||||
@@ -103,7 +88,7 @@
|
||||
|
||||
- name: Copy kubectl config to local machine
|
||||
ansible.builtin.fetch:
|
||||
src: ~{{ ansible_user }}/.kube/config
|
||||
src: /etc/rancher/k3s/k3s.yaml
|
||||
dest: "{{ kubeconfig }}"
|
||||
flat: true
|
||||
|
||||
@@ -171,11 +156,41 @@
|
||||
delay: 10
|
||||
changed_when: false
|
||||
|
||||
- name: Create symlinks
|
||||
ansible.builtin.file:
|
||||
src: /usr/local/bin/k3s
|
||||
dest: /usr/local/bin/{{ item }}
|
||||
state: link
|
||||
with_items:
|
||||
- kubectl
|
||||
- crictl
|
||||
- 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:
|
||||
src: /usr/local/bin/k3s
|
||||
dest: /usr/local/bin/kubectl
|
||||
state: link
|
||||
|
||||
- name: Create directory .kube
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user