It changes the directory layout of the ansible playbook to a more "best practices" friendly approach using ansible roles and a real inventory file Co-authored-by: Ilya Kreymer <ikreymer@users.noreply.github.com>
		
			
				
	
	
		
			92 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
			
		
		
	
	
			92 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
| ---
 | |
| 
 | |
| - name: Copy K3s service file
 | |
|   register: k3s_service
 | |
|   template:
 | |
|     src: "k3s.service.j2"
 | |
|     dest: "{{ systemd_dir }}/k3s.service"
 | |
|     owner: root
 | |
|     group: root
 | |
|     mode: 0644
 | |
| 
 | |
| - name: Enable and check K3s service
 | |
|   systemd:
 | |
|     name: k3s
 | |
|     daemon_reload: yes
 | |
|     state: started
 | |
|     enabled: yes
 | |
| 
 | |
| - name: Wait for node-token
 | |
|   wait_for:
 | |
|     path: "{{ k3s_server_location }}/server/node-token"
 | |
| 
 | |
| - name: Register node-token file access mode
 | |
|   stat:
 | |
|     path: "{{ k3s_server_location }}/server/node-token"
 | |
|   register: p
 | |
| 
 | |
| - name: Change file access node-token
 | |
|   file:
 | |
|     path: "{{ k3s_server_location }}/server/node-token"
 | |
|     mode: "g+rx,o+rx"
 | |
| 
 | |
| - name: Read node-token from master
 | |
|   slurp:
 | |
|     path: "{{ k3s_server_location }}/server/node-token"
 | |
|   register: node_token
 | |
| 
 | |
| - name: Store Master node-token
 | |
|   set_fact:
 | |
|     token: "{{ node_token.content | b64decode | regex_replace('\n', '') }}"
 | |
| 
 | |
| - name: Restore node-token file access
 | |
|   file:
 | |
|     path: "{{ k3s_server_location }}/server/node-token"
 | |
|     mode: "{{ p.stat.mode }}"
 | |
| 
 | |
| - name: Create directory .kube
 | |
|   file:
 | |
|     path: ~{{ ansible_user }}/.kube
 | |
|     state: directory
 | |
|     owner: "{{ ansible_user }}"
 | |
|     mode: "u=rwx,g=rx,o="
 | |
| 
 | |
| - name: Copy config file to user home directory
 | |
|   copy:
 | |
|     src: /etc/rancher/k3s/k3s.yaml
 | |
|     dest: ~{{ ansible_user }}/.kube/config
 | |
|     remote_src: yes
 | |
|     owner: "{{ ansible_user }}"
 | |
|     mode: "u=rw,g=,o="
 | |
| 
 | |
| - name: Replace https://localhost:6443 by https://controller-ip:6443
 | |
|   command: >-
 | |
|     k3s kubectl config set-cluster default
 | |
|       --server=https://{{ controller_ip }}:6443
 | |
|       --kubeconfig ~{{ ansible_user }}/.kube/config    
 | |
|   changed_when: true
 | |
| 
 | |
| - name: Check that the kubectl binary exists
 | |
|   stat:
 | |
|     path: /usr/local/bin/kubectl
 | |
|   register: kubectl_result
 | |
| 
 | |
| - name: Check that the crictl binary exists
 | |
|   stat:
 | |
|     path: /usr/local/bin/crictl
 | |
|   register: crictl_result
 | |
| 
 | |
| - name: Create kubectl symlink
 | |
|   file:
 | |
|     src: /usr/local/bin/k3s
 | |
|     dest: /usr/local/bin/kubectl
 | |
|     state: link
 | |
|   when: not kubectl_result.stat.exists
 | |
| 
 | |
| - name: Create crictl symlink
 | |
|   file:
 | |
|     src: /usr/local/bin/k3s
 | |
|     dest: /usr/local/bin/crictl
 | |
|     state: link
 | |
|   when: not crictl_result.stat.exists
 |