|
1 | 1 | - name: Download k3s binary
|
2 |
| - get_url: |
| 2 | + ansible.builtin.get_url: |
3 | 3 | url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s
|
4 | 4 | checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-amd64.txt
|
5 | 5 | dest: "{{ role_path }}/files/bin/k3s"
|
| 6 | + mode: 0755 |
6 | 7 | delegate_to: localhost
|
7 | 8 | run_once: true
|
8 | 9 | register: k3s_binary
|
9 | 10 |
|
10 | 11 | - name: Copy k3s binary to nodes
|
11 |
| - copy: |
| 12 | + ansible.builtin.copy: |
12 | 13 | src: bin/k3s
|
13 | 14 | dest: /usr/local/bin/k3s
|
14 | 15 | owner: root
|
15 | 16 | group: root
|
16 | 17 | mode: 0755
|
17 | 18 |
|
18 | 19 | - name: Ensure config directories exist
|
19 |
| - file: |
| 20 | + ansible.builtin.file: |
20 | 21 | path: "{{ item }}"
|
21 | 22 | state: directory
|
22 | 23 | mode: 0755
|
|
26 | 27 |
|
27 | 28 | - name: Check if k3s token file exists on the first node
|
28 | 29 | run_once: true
|
29 |
| - stat: |
| 30 | + ansible.builtin.stat: |
30 | 31 | path: "{{ k3s_token_file }}"
|
31 | 32 | register: k3s_token_file_stat
|
32 | 33 |
|
33 | 34 | - name: Generate k3s token file on the first node if not exist yet
|
34 | 35 | run_once: true
|
35 | 36 | when: not k3s_token_file_stat.stat.exists
|
36 |
| - copy: |
| 37 | + ansible.builtin.copy: |
37 | 38 | content: "{{ lookup('community.general.random_string', length=32) }}"
|
38 | 39 | dest: "{{ k3s_token_file }}"
|
39 | 40 | mode: 0600
|
40 | 41 |
|
41 | 42 | - name: Get k3s token from the first node
|
42 | 43 | run_once: true
|
43 |
| - slurp: |
| 44 | + ansible.builtin.slurp: |
44 | 45 | src: "{{ k3s_token_file }}"
|
45 | 46 | register: k3s_token_base64
|
46 | 47 |
|
47 | 48 | - name: Ensure all nodes has the same token
|
48 |
| - copy: |
| 49 | + ansible.builtin.copy: |
49 | 50 | content: "{{ k3s_token_base64.content | b64decode }}"
|
50 | 51 | dest: "{{ k3s_token_file }}"
|
51 | 52 | mode: 0600
|
52 | 53 |
|
53 | 54 | - name: Copy k3s config files
|
54 |
| - template: |
| 55 | + ansible.builtin.template: |
55 | 56 | src: "{{ item.src }}"
|
56 | 57 | dest: "{{ item.dest }}"
|
57 | 58 | mode: 0644
|
|
62 | 63 | dest: "{{ k3s_service_file }}"
|
63 | 64 |
|
64 | 65 | - name: Enable k3s service
|
65 |
| - systemd: |
| 66 | + ansible.builtin.systemd: |
66 | 67 | name: k3s
|
67 | 68 | enabled: true
|
68 | 69 | state: started
|
|
72 | 73 |
|
73 | 74 | - name: Get Kubernetes config file
|
74 | 75 | run_once: true
|
75 |
| - slurp: |
| 76 | + ansible.builtin.slurp: |
76 | 77 | src: /etc/rancher/k3s/k3s.yaml
|
77 | 78 | register: kubeconfig_base64
|
78 | 79 |
|
79 | 80 | - name: Write Kubernetes config file with the correct cluster address
|
80 |
| - copy: |
| 81 | + ansible.builtin.copy: |
81 | 82 | content: "{{ kubeconfig_base64.content | b64decode | replace('127.0.0.1', hostvars[groups['masters'][0]].ansible_host) }}"
|
82 | 83 | dest: "{{ playbook_dir }}/kubeconfig.yaml"
|
83 | 84 | mode: 0600
|
|
0 commit comments