diff --git a/create.yaml b/create.yaml index ba0d161..5be3d3a 100644 --- a/create.yaml +++ b/create.yaml @@ -2,17 +2,8 @@ hosts: localhost connection: local # FIXME: create volume role - tasks: - - name: Create the home volume - hetzner.hcloud.volume: - # FIXME: put to vars - # FIXME: add mount to server - # FIXME: gpart create -s GPT da1 && gpart add -t freebsd-zfs -l storage -a 1M da1 && zpool create -f home da1 - name: home - location: fsn1 - format: ext4 - size: 100 - state: present + roles: + - storage - name: Create BSDNIX Servers hosts: vps diff --git a/group_vars/all/all.yaml b/group_vars/all/all.yaml index 67d37c6..7aa4d2c 100644 --- a/group_vars/all/all.yaml +++ b/group_vars/all/all.yaml @@ -22,3 +22,10 @@ ssh_keys: jails: pubnix: octet: 2 + +storage: + home: + size: 10 + name: zhcloud # zfs pool name + mount: /home + device: da1 diff --git a/roles/install/tasks/main.yaml b/roles/install/tasks/main.yaml index 6bac4d8..62e201f 100644 --- a/roles/install/tasks/main.yaml +++ b/roles/install/tasks/main.yaml @@ -1,6 +1,6 @@ --- - name: Create server - hcloud_server: + hetzner.hcloud.server: name: "{{ hostname }}" server_type: "{{ type }}" image: "{{ image }}" @@ -8,12 +8,12 @@ enable_ipv4: false state: present ssh_keys: "{{ ssh_keys }}" + # FIXME: https://github.com/ansible-collections/hetzner.hcloud/issues/585 + #volumes: "{{ storage.home.name }}" register: server -# - command: which python -# register: result - -# - name: Install Packages -# community.general.pkgng: -# state: present -# name: "{{ packages }}" +- name: Attach the home volume + hetzner.hcloud.volume: + name: "{{ storage.home.name }}" + server: "{{ hostname }}" + state: present diff --git a/roles/remove/tasks/main.yaml b/roles/remove/tasks/main.yaml index 500530c..a3a74c4 100644 --- a/roles/remove/tasks/main.yaml +++ b/roles/remove/tasks/main.yaml @@ -1,7 +1,7 @@ --- - name: Remove volume hetzner.hcloud.volume: - name: home + name: "{{ storage.home.name }}" state: absent - name: Remove server diff --git a/roles/server/tasks/main.yaml b/roles/server/tasks/main.yaml index f1e8389..1d25d2c 100644 --- a/roles/server/tasks/main.yaml +++ b/roles/server/tasks/main.yaml @@ -4,6 +4,33 @@ state: present name: "{{ packages }}" -- command: which cpdup - register: result +# FIXME: remove the symlink in the release snapshot +- name: Remove old home sym link + shell: | + rm /home + touch /tmp/.ansible.home + args: + creates: "/tmp/.ansible.home" + +- name: Setup home volume partition + shell: | + gpart create -s GPT da1 + touch /tmp/.ansible.gpt + args: + creates: "/tmp/.ansible.gpt" +- name: Setup home fs type + shell: "gpart add -t freebsd-zfs -l {{ storage.home.name }} -a 1M {{ storage.home.device }}" + args: + creates: "/dev/da1p1" + + +- name: Create zpool using home volume + shell: "zpool create -f {{ storage.home.name }} {{ storage.home.device }}" + args: + creates: "/{{ storage.home.name }}" + +- name: Create zfs home dataset + shell: "zfs create -o mountpoint={{ storage.home.mount }} {{ storage.home.name }}/home" + args: + creates: "/home" diff --git a/roles/storage/tasks/main.yaml b/roles/storage/tasks/main.yaml new file mode 100644 index 0000000..ec9e150 --- /dev/null +++ b/roles/storage/tasks/main.yaml @@ -0,0 +1,7 @@ +--- +- name: Create the home volume + hetzner.hcloud.volume: + name: "{{ storage.home.name }}" + location: "{{ location }}" + size: "{{ storage.home.size }}" + state: present