Skip to content

Commit

Permalink
feat: add zfs ansible scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisDuarte1 committed Nov 9, 2024
1 parent 8bf3358 commit 2169624
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ansible-inventory.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
# if you wish, you can specify an alias for a node, or you can just specify
# the ip address as shown below:

# you need to always define the ansible_ssh_host and ansible_ssh_private_key because they will be changed automatically
# you need to always define the ansible_ssh_host and ansible_ssh_private_key_file because they will be changed automatically
# you maybe to need to define the external interface (that will be given to the router, alongside the whole PCI device).


#node1 ansible_ssh_host=10.0.0.2 ansible_ssh_private_key=/path/to/private_key
#node1 ansible_ssh_host=10.0.0.2 ansible_ssh_private_key=/path/to/private_key external_interface=enp1f0
#node1 ansible_ssh_host=10.0.0.2 ansible_ssh_private_key_file=/path/to/private_key
#node1 ansible_ssh_host=10.0.0.2 ansible_ssh_private_key_file=/path/to/private_key external_interface=enp1f0


#any node can be used to setup zfs pools
#node2 ansible_ssh_host=192.168.121.184 ansible_user=ni ansible_ssh_private_key_file=node/bootstrap_key storage=true


[workers]
Expand Down
23 changes: 23 additions & 0 deletions maintenance/update-all-playbook-no-restart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

- name: Update all nodes
hosts: nodes
become: true
tasks:
- name: Update nodes using DNF # noqa: package-latest
ansible.builtin.dnf:
name: "*"
update_cache: true
update_only: true
state: latest

- name: Update all routers
hosts: routers
become: true
tasks:
- name: Update nodes using APT
ansible.builtin.apt:
name: "*"
update_cache: true
only_upgrade: true
state: latest
103 changes: 103 additions & 0 deletions node/add-zfs-to-storage-node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
- name: Add zfs to storage nodes
hosts: all
become: true
vars:
zfs_pool_name: "niployments-hard-storage"
zfs_pool_mountpoint: "/mnt/hard-storage"
zfs_pool_state: present
zfs_pool_mode: "raidz"

tasks:
- name: Only run play if storage is not enabled
when: hostvars[inventory_hostname]['storage'] is defined and hostvars[inventory_hostname]['storage'] == "true"
block:
- name: Get stoarge definitions
ansible.builtin.include_vars:
file: storage-defs.json
name: storage_definitions
- name: Use storage definition for node
ansible.builtin.set_fact:
zfs_pool_devices: "{{ storage_definitions[inventory_hostname] }}"
- name: Enable EPEL repository

Check failure on line 22 in node/add-zfs-to-storage-node.yaml

View workflow job for this annotation

GitHub Actions / Ansible Lint

fqcn[action-core]

Use FQCN for builtin module actions (ansible.builtin.yum).

Check failure

Code scanning / Ansible-lint

Use FQCN for builtin module actions (ansible.builtin.yum). Error

Use ansible.builtin.dnf or ansible.legacy.dnf instead.
ansible.builtin.yum:
name: epel-release
state: present
- name: Add ZFS GPG key
ansible.builtin.rpm_key:
state: present
key: https://raw.githubusercontent.com/zfsonlinux/zfsonlinux.github.com/master/zfs-release/RPM-GPG-KEY-openzfs-key2
- name: Install DKMS manually

Check failure on line 30 in node/add-zfs-to-storage-node.yaml

View workflow job for this annotation

GitHub Actions / Ansible Lint

fqcn[action-core]

Use FQCN for builtin module actions (ansible.builtin.yum).

Check failure

Code scanning / Ansible-lint

Use FQCN for builtin module actions (ansible.builtin.yum). Error

Use ansible.builtin.dnf or ansible.legacy.dnf instead.
ansible.builtin.yum:
name: dkms
state: present
- name: Install zfs repo

Check failure on line 34 in node/add-zfs-to-storage-node.yaml

View workflow job for this annotation

GitHub Actions / Ansible Lint

fqcn[action-core]

Use FQCN for builtin module actions (ansible.builtin.yum).

Check failure

Code scanning / Ansible-lint

Use FQCN for builtin module actions (ansible.builtin.yum). Error

Use ansible.builtin.dnf or ansible.legacy.dnf instead.
ansible.builtin.yum:
name: "https://zfsonlinux.org/epel/zfs-release-2-3.el9.noarch.rpm"
state: present
- name: Install ZFS
ansible.builtin.dnf:
name:
- zfs
- zfs-dkms
- kernel-devel
state: present
- name: Install dkms modules
ansible.builtin.command: dkms autoinstall
changed_when: true
- name: Load ZFS kernel module

Check failure on line 48 in node/add-zfs-to-storage-node.yaml

View workflow job for this annotation

GitHub Actions / Ansible Lint

ignore-errors

Use failed_when and specify error conditions instead of using ignore_errors.

Check failure

Code scanning / Ansible-lint

Use failed_when and specify error conditions instead of using ignore_errors. Error

Task/Handler: Load ZFS kernel module
ansible.builtin.command: modprobe zfs
changed_when: true
ignore_errors: yes

Check failure on line 51 in node/add-zfs-to-storage-node.yaml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[truthy]

Truthy value should be one of \[false, true]

Check failure

Code scanning / Ansible-lint

Truthy value should be one of [false, true] Error

Truthy value should be one of [false, true]
- name: Check ZFS pool existance

Check failure on line 52 in node/add-zfs-to-storage-node.yaml

View workflow job for this annotation

GitHub Actions / Ansible Lint

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure

Code scanning / Ansible-lint

Use FQCN for builtin module actions (ansible.builtin.yum). Error

Use ansible.builtin.command or ansible.legacy.command instead.
command: zpool list -Ho name {{ zfs_pool_name }}
register: result_pool_list
ignore_errors: yes

Check failure on line 55 in node/add-zfs-to-storage-node.yaml

View workflow job for this annotation

GitHub Actions / Ansible Lint

yaml[truthy]

Truthy value should be one of \[false, true]

Check failure

Code scanning / Ansible-lint

Truthy value should be one of [false, true] Error

Truthy value should be one of [false, true]
changed_when: false

- name: Create ZFS pool

Check failure on line 58 in node/add-zfs-to-storage-node.yaml

View workflow job for this annotation

GitHub Actions / Ansible Lint

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 58 in node/add-zfs-to-storage-node.yaml

View workflow job for this annotation

GitHub Actions / Ansible Lint

no-changed-when

Commands should not change things if nothing needs doing.

Check failure

Code scanning / Ansible-lint

Use FQCN for builtin module actions (ansible.builtin.yum). Error

Use ansible.builtin.command or ansible.legacy.command instead.

Check failure

Code scanning / Ansible-lint

Commands should not change things if nothing needs doing. Error

Task/Handler: Create ZFS pool
command: >-
zpool create
{{ '-m ' + zfs_pool_mountpoint if zfs_pool_mountpoint else '' }}
{{ zfs_pool_name }}
{{ zfs_pool_mode if zfs_pool_mode else '' }}
{{ zfs_pool_devices | join(' ') }}
when:
- zfs_pool_state | default('present') == 'present'
- result_pool_list.rc == 1
- name: Install NFS utilities

Check failure on line 68 in node/add-zfs-to-storage-node.yaml

View workflow job for this annotation

GitHub Actions / Ansible Lint

fqcn[action-core]

Use FQCN for builtin module actions (dnf).

Check failure

Code scanning / Ansible-lint

Use FQCN for builtin module actions (ansible.builtin.yum). Error

Use ansible.builtin.dnf or ansible.legacy.dnf instead.
dnf:
name: nfs-utils
state: present

- name: Force nfs version 4

Check failure

Code scanning / Ansible-lint

Trailing spaces Error

Trailing spaces
ansible.builtin.lineinfile:
path: /etc/nfsmount.conf
regexp: "^# Nfsvers=4"
line: "Nfsvers=4"
- name: Enable and start the NFS server service
ansible.builtin.systemd:
name: nfs-server
enabled: true
state: started

- name: Create export directory
ansible.builtin.file:
path: "{{ zfs_pool_mountpoint }}/shared_dir"
state: directory
mode: '0755'

- name: Set SELinux context for the export directory
ansible.builtin.command: chcon -t nfs_t {{ zfs_pool_mountpoint }}/shared_dir
args:
creates: /export/shared_dir

- name: Configure NFS exports

Check failure

Code scanning / Ansible-lint

`mode: 644` should have a string value with leading zero `mode: "01204"` or use symbolic mode. Error

Task/Handler: Configure NFS exports
ansible.builtin.copy:
dest: /etc/exports
content: "{{ zfs_pool_mountpoint }}/shared_dir *(rw,sync,no_root_squash,no_subtree_check)\n"
mode: 644

- name: Export NFS shares
ansible.builtin.command: exportfs -r
changed_when: true

Check failure

Code scanning / Ansible-lint

No new line character at the end of file Error

No new line character at the end of file
7 changes: 7 additions & 0 deletions node/vars/storage-defs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"cluster2": [
"/dev/disk/by-id/ata-ST2000DM008-2UB102_WFL7F5R8",
"/dev/disk/by-id/ata-ST2000DM008-2UB102_WFL7F74S",
"/dev/disk/by-id/ata-ST2000DM008-2UB102_WFL7HRE3"
]
}

0 comments on commit 2169624

Please sign in to comment.