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:
commit
94853447fc
8 changed files with 79 additions and 0 deletions
9
group-k3s.yml
Normal file
9
group-k3s.yml
Normal 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
11
host-plumbum.yml
Normal 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
|
|
@ -1,2 +1,3 @@
|
|||
---
|
||||
server_admin: "admin+plumbum@netz39.de"
|
||||
mac: "32:A3:94:A0:23:77"
|
||||
|
|
3
main.yml
3
main.yml
|
@ -39,3 +39,6 @@
|
|||
|
||||
- name: Hobbes specific setup
|
||||
import_playbook: host-hobbes.yml
|
||||
|
||||
- name: Plumbum specific setup
|
||||
import_playbook: host-plumbum.yml
|
||||
|
|
8
roles/nfs-host/defaults/main.yml
Normal file
8
roles/nfs-host/defaults/main.yml
Normal 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"
|
3
roles/nfs-host/handlers/main.yml
Normal file
3
roles/nfs-host/handlers/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
- name: reload nfs
|
||||
command: 'exportfs -ra'
|
41
roles/nfs-host/tasks/main.yml
Normal file
41
roles/nfs-host/tasks/main.yml
Normal 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
|
3
roles/nfs-host/templates/exports.j2
Normal file
3
roles/nfs-host/templates/exports.j2
Normal file
|
@ -0,0 +1,3 @@
|
|||
{% for export in nfs_host_exports %}
|
||||
{{ export.directory }} {{ export.hosts }}({{ export.options }})
|
||||
{% endfor %}
|
Loading…
Reference in a new issue