Merge pull request 'initial plan for storage host role' (!229) from feat/k3s-storage-host into master

Reviewed-on: Netz39_Admin/netz39-infra-ansible#229
Reviewed-by: Stefan Haun <tux@netz39.de>
This commit is contained in:
Stefan Haun 2023-11-04 17:18:00 +01:00
commit 94853447fc
8 changed files with 79 additions and 0 deletions

9
group-k3s.yml Normal file
View file

@ -0,0 +1,9 @@
---
- hosts: k3s
become: true
tasks:
- name: Ensure nfs-common is installed on k3s VMs
ansible.builtin.apt:
pkg: nfs-common
state: present

11
host-plumbum.yml Normal file
View file

@ -0,0 +1,11 @@
---
- hosts: plumbum.n39.eu
become: true
roles:
- role: nfs-host
vars:
nfs_host_exports:
- directory: "/srv/nfs"
hosts: "*.n39.eu"
options: rw,sync,no_subtree_check

View file

@ -1,2 +1,3 @@
--- ---
server_admin: "admin+plumbum@netz39.de"
mac: "32:A3:94:A0:23:77" mac: "32:A3:94:A0:23:77"

View file

@ -39,3 +39,6 @@
- name: Hobbes specific setup - name: Hobbes specific setup
import_playbook: host-hobbes.yml import_playbook: host-hobbes.yml
- name: Plumbum specific setup
import_playbook: host-plumbum.yml

View file

@ -0,0 +1,8 @@
# Defaults for nfs-host
---
nfs_host_exports: []
# - directory: "/srv/nfs"
# hosts: "k3s-w[0-9]+.n39.eu"
# options: rw,sync,no_subtree_check
nfs_host_storage_device: "/dev/sdb"

View file

@ -0,0 +1,3 @@
---
- name: reload nfs
command: 'exportfs -ra'

View file

@ -0,0 +1,41 @@
---
- name: Install required packages
ansible.builtin.apt:
state: present
name:
- nfs-kernel-server
- nfs-common
- parted
- name: Create a new ext4 primary partition
community.general.parted:
device: "{{ nfs_host_storage_device }}"
number: 1
state: present
fs_type: ext4
- name: ensure nfs mountpoints exist
ansible.builtin.file:
path: "{{ item.directory }}"
state: directory
owner: nobody
group: nogroup
mode: '0777'
with_items: "{{ nfs_host_exports }}"
- name: Mount up device by label
ansible.posix.mount:
path: "{{ nfs_host_exports[0].directory }}"
src: /dev/sdb1
fstype: ext4
state: present
- name: template /etc/exports
ansible.builtin.template:
src: templates/exports.j2
dest: "/etc/exports"
notify: reload nfs
- name: Ensure nfs is running.
ansible.builtin.service: "name=nfs-kernel-server state=started enabled=yes"
when: nfs_host_exports|length

View file

@ -0,0 +1,3 @@
{% for export in nfs_host_exports %}
{{ export.directory }} {{ export.hosts }}({{ export.options }})
{% endfor %}