initial commit

This commit is contained in:
2023-11-19 14:57:18 +03:00
commit 097ce0a6cf
11 changed files with 876 additions and 0 deletions

20
tasks/configuration.yml Normal file
View File

@@ -0,0 +1,20 @@
---
- name: Create env for k3s master node
template:
src: k3s-master-service-env.j2
dest: /etc/systemd/system/k3s.service.env
register: k3s_env
- name: Create systemd unit k3s for master
template:
src: k3s-master-service.j2
dest: /etc/systemd/system/k3s.service
register: k3s_master
- name: Startup unit for master node
systemd:
state: started
daemon_reload: true
enabled: yes
name: k3s
when: k3s_env.changed or k3s_master.changed

35
tasks/installation.yml Normal file
View File

@@ -0,0 +1,35 @@
---
- name: Download k3s binary x64
get_url:
url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-amd64.txt
dest: "{{ k3s_binary_dir }}/{{ k3s_binary_name }}"
owner: root
group: root
mode: 0755
when: ansible_facts.architecture == "x86_64"
- name: Download k3s binary arm64
get_url:
url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s-arm64
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-arm64.txt
dest: "{{ k3s_binary_dir }}/{{ k3s_binary_name }}"
owner: root
group: root
mode: 0755
when:
- ( ansible_facts.architecture is search("arm") and
ansible_facts.userspace_bits == "64" ) or
ansible_facts.architecture is search("aarch64")
- name: Download k3s binary armhf
get_url:
url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s-armhf
checksum: sha256:https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/sha256sum-arm.txt
dest: "{{ k3s_binary_dir }}/{{ k3s_binary_name }}"
owner: root
group: root
mode: 0755
when:
- ansible_facts.architecture is search("arm")
- ansible_facts.userspace_bits == "32"

15
tasks/main.yml Normal file
View File

@@ -0,0 +1,15 @@
---
- name: check if binary already exists
stat:
path: "{{ k3s_binary_dir }}/{{ k3s_binary_name }}"
register: binary_check_result
- name: install binary
include_tasks: installation.yml
when: not binary_check_result.stat.exists or k3s_force_update
- name: general preparation
include_tasks: preparation.yml
- name: configuration
include_tasks: configuration.yml

60
tasks/preparation.yml Normal file
View File

@@ -0,0 +1,60 @@
---
- name: Disable SWAP in fstab since kubernetes can't work with swap enabled
replace:
path: /etc/fstab
regexp: '^([^#].*?\sswap\s+sw\s+.*)$'
replace: '# \1'
register: swapoff
- name: Disable SWAP since kubernetes can't work with swap enabled
shell: swapoff -a
when: swapoff.changed
- name: Enable IPv4 forwarding
sysctl:
name: net.ipv4.ip_forward
value: "1"
state: present
reload: yes
- name: Enable IPv6 forwarding
sysctl:
name: net.ipv6.conf.all.forwarding
value: "1"
state: present
reload: yes
when: ansible_all_ipv6_addresses
- name: Add br_netfilter to /etc/modules-load.d/
copy:
content: "br_netfilter"
dest: /etc/modules-load.d/br_netfilter.conf
mode: "u=rw,g=,o="
when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux']
- name: Load br_netfilter
modprobe:
name: br_netfilter
state: present
when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux']
- name: Set bridge-nf-call-iptables (just to be sure)
sysctl:
name: "{{ item }}"
value: "1"
state: present
reload: yes
when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux']
loop:
- net.bridge.bridge-nf-call-iptables
- net.bridge.bridge-nf-call-ip6tables
- name: Add /usr/local/bin to sudo secure_path
lineinfile:
line: 'Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin'
regexp: "Defaults(\\s)*secure_path(\\s)*="
state: present
insertafter: EOF
path: /etc/sudoers
validate: 'visudo -cf %s'
when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux']