From ba594fe84e31e43be183a67bd3d6bdd4974e8be2 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Mon, 30 Sep 2024 17:06:23 +0100 Subject: [PATCH] ansible: add swapfile creation for FreeBSD --- ansible/inventory.yml | 2 +- .../bootstrap/tasks/partials/freebsd.yml | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 ansible/roles/bootstrap/tasks/partials/freebsd.yml diff --git a/ansible/inventory.yml b/ansible/inventory.yml index 9442f2a8d..a65cbe425 100644 --- a/ansible/inventory.yml +++ b/ansible/inventory.yml @@ -122,7 +122,7 @@ hosts: fedora40-x64-2: {ip: 162.243.187.89} freebsd12-x64-1: {ip: 45.55.90.237, user: freebsd} freebsd12-x64-2: {ip: 107.170.28.213, user: freebsd} - freebsd13-x64-1: {ip: 138.197.25.49, user: freebsd} + freebsd13-x64-1: {ip: 138.197.25.49, user: freebsd, swap_file_size_mb: 2048} rhel8-x64-1: {ip: 161.35.139.78, build_test_v8: yes, swap_file_size_mb: 2048} rhel9-x64-1: {ip: 134.122.12.240, swap_file_size_mb: 2048} ubuntu2204_docker-x64-1: {ip: 134.209.55.216} diff --git a/ansible/roles/bootstrap/tasks/partials/freebsd.yml b/ansible/roles/bootstrap/tasks/partials/freebsd.yml new file mode 100644 index 000000000..c0a51301c --- /dev/null +++ b/ansible/roles/bootstrap/tasks/partials/freebsd.yml @@ -0,0 +1,39 @@ +--- + +# +# FreeBSD +# + +# Assumes swap_file_size_mb has been set. +- name: create swapfile + ansible.builtin.command: + cmd: dd if=/dev/zero of=/{{ swap_file }} bs=1M count={{ swap_file_size_mb }} + creates: "{{ swap_file }}" + become: yes + become_user: root + register: swap_create + +- name: set swapfile permissions + ansible.builtin.file: + mode: 0600 + owner: root + path: "{{ swap_file }}" + +- name: set up swap area + ansible.builtin.command: + cmd: mdconfig -a -t vnode -f {{ swap_file }} -u 0 + when: swap_create.changed + +- name: enable swap + ansible.builtin.command: + cmd: swapon /dev/md0 + when: swap_create.changed + +- name: add swap to fstab + ansible.posix.mount: + fstype: swap + opts: "sw,file={{ swap_file }},late" + path: none + src: md0 + state: present + when: swap_create.changed