Files
home-cluster/bootstrap/templates/ansible/playbooks/cluster-prepare.yaml.j2
T
2024-02-02 18:02:14 -05:00

114 lines
4.2 KiB
YAML

---
- name: Prepare System
hosts: kubernetes
become: true
gather_facts: true
any_errors_fatal: true
pre_tasks:
- name: Pausing for 5 seconds...
ansible.builtin.pause:
seconds: 5
- name: Populate service facts
ansible.builtin.service_facts:
tasks:
- name: Locale
block:
- name: Locale | Set timezone
community.general.timezone:
name: "{{ timezone }}"
- name: Packages
block:
- name: Packages | Install
ansible.builtin.apt:
name: apt-transport-https,ca-certificates,conntrack,curl,dirmngr,gdisk,gnupg,hdparm,htop,
iptables,iputils-ping,ipvsadm,libseccomp2,lm-sensors,net-tools,nfs-common,
nvme-cli,open-iscsi,parted,psmisc,python3,python3-apt,python3-kubernetes,python3-yaml,
smartmontools,socat,software-properties-common,unzip,util-linux
install_recommends: false
- name: Network Configuration
notify: Reboot
block:
- name: Network Configuration | Set hostname
ansible.builtin.hostname:
name: "{% raw %}{{ inventory_hostname }}{% endraw %}"
- name: Network Configuration | Update hosts
ansible.builtin.copy:
content: |
127.0.0.1 localhost
127.0.1.1 {% raw %}{{ inventory_hostname }}{% endraw %}
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
dest: /etc/hosts
mode: preserve
# https://github.com/onedr0p/cluster-template/discussions/635
- name: Network Configuration | Remove immutable flag from /etc/resolv.conf
ansible.builtin.file:
attributes: -i
path: /etc/resolv.conf
- name: Network Configuration | Remove /etc/resolv.conf
ansible.builtin.file:
attributes: -i
path: /etc/resolv.conf
state: absent
- name: Network Configuration | Add custom /etc/resolv.conf
ansible.builtin.copy:
attributes: +i
mode: '0644'
dest: /etc/resolv.conf
content: |
search {{ nodes.search_domain|default('.', true) }}
{% for item in nodes.dns_servers | default(['1.1.1.1', '1.0.0.1']) %}
nameserver {{ item }}
{% endfor %}
- name: System Configuration
notify: Reboot
block:
- name: System Configuration | Disable apparmor
when: ansible_facts.services['apparmor.service'] is defined
ansible.builtin.systemd:
name: apparmor
state: stopped
masked: true
- name: System Configuration | Disable swap
ansible.posix.mount:
name: "{% raw %}{{ item }}{% endraw %}"
fstype: swap
state: absent
loop: ["none", "swap"]
- name: System Configuration | Create Kernel modules
ansible.builtin.copy:
dest: "/etc/modules-load.d/{% raw %}{{ item }}{% endraw %}.conf"
mode: "0644"
content: "{% raw %}{{ item }}{% endraw %}"
loop: ["br_netfilter", "ceph", "ip_vs", "ip_vs_rr", "nbd", "overlay", "rbd"]
register: modules_status
- name: System Configuration | Reload Kernel modules # noqa: no-changed-when no-handler
when: modules_status.changed
ansible.builtin.systemd:
name: systemd-modules-load
state: restarted
- name: System Configuration | Sysctl
ansible.posix.sysctl:
name: "{% raw %}{{ item.key }}{% endraw %}"
value: "{% raw %}{{ item.value }}{% endraw %}"
sysctl_file: /etc/sysctl.d/99-kubernetes.conf
reload: true
with_dict: "{% raw %}{{ sysctl_config }}{% endraw %}"
vars:
sysctl_config:
fs.inotify.max_queued_events: 65536
fs.inotify.max_user_watches: 524288
fs.inotify.max_user_instances: 8192
handlers:
- name: Reboot
ansible.builtin.reboot:
msg: Rebooting hosts
reboot_timeout: 3600