From 1ab99a97a9dc6608ba85e8e2a4eb41a85c7e297e Mon Sep 17 00:00:00 2001 From: pullyvan <pullyvan.kris@gmail.com> Date: Tue, 1 Feb 2022 13:19:45 +0100 Subject: [PATCH 1/5] fix crash on creating partition table GPT by adding a ignore_errors condition and double the command first to make the device nvme visible then to format it --- tasks/ubuntu2004.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tasks/ubuntu2004.yml b/tasks/ubuntu2004.yml index 9379da7..48c230a 100644 --- a/tasks/ubuntu2004.yml +++ b/tasks/ubuntu2004.yml @@ -36,6 +36,15 @@ state: unmounted ignore_errors: yes +- name: Make nvme visible on /dev/ + community.general.parted: + device: "{{ dev }}" + number: 1 + state: present + fs_type: "{{ fstype }}" + label: gpt + ignore_errors: yes + - name: Create a new partition on disk community.general.parted: device: "{{ dev }}" @@ -43,6 +52,7 @@ state: present fs_type: "{{ fstype }}" label: gpt + ignore_errors: yes - name: Create a filesystem on device community.general.filesystem: -- GitLab From f457e1d97218238c6598eb367f18bc99f46c0c3d Mon Sep 17 00:00:00 2001 From: pullyvan <pullyvan.kris@gmail.com> Date: Tue, 1 Feb 2022 16:59:47 +0100 Subject: [PATCH 2/5] fix device not found by adding a check if device exists and destroy and recreate it if it does --- defaults/main.yml | 1 + tasks/ubuntu2004.yml | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 22ca5fe..03830c4 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -5,3 +5,4 @@ dev: /dev/nvme0n1 mount: /home opts: "rw" state: mounted +devpart: nvme0n1p1 \ No newline at end of file diff --git a/tasks/ubuntu2004.yml b/tasks/ubuntu2004.yml index 48c230a..8031fce 100644 --- a/tasks/ubuntu2004.yml +++ b/tasks/ubuntu2004.yml @@ -22,28 +22,32 @@ - name: "Check if {{ dev }} exists" stat: path: "{{ dev }}" + register: device_exist -- name: Unmount a mounted volume - ansible.posix.mount: - path: "{{ mount }}" - state: unmounted - ignore_errors: yes - +- name: "Check if {{ devpart }} exists" + stat: + path: "{{ dev }}" + register: devpart_exist -- name: Unmount a mounted folder +- name: "Unmount a {{ mount }} mounted volume" ansible.posix.mount: path: "{{ mount }}" state: unmounted ignore_errors: yes -- name: Make nvme visible on /dev/ +- name: Delete a first partition on disk community.general.parted: device: "{{ dev }}" number: 1 - state: present + state: absent fs_type: "{{ fstype }}" label: gpt - ignore_errors: yes + when: devpart_exist.stat.islnk is defined + +- name: "Check if {{ devpart }} exists" + stat: + path: "{{ dev }}" + register: devpart2_exist - name: Create a new partition on disk community.general.parted: @@ -52,13 +56,15 @@ state: present fs_type: "{{ fstype }}" label: gpt - ignore_errors: yes + when: devpart2_exist.stat.islnk == False + - name: Create a filesystem on device community.general.filesystem: fstype: "{{ fstype }}" dev: "{{ dev }}p1" force: yes + when: devpart2_exist.stat.islnk == False - name: Mount up device on folder in fstab mount: @@ -66,6 +72,7 @@ src: "{{ dev }}p1" fstype: "{{ fstype }}" state: present + when: devpart2_exist.stat.islnk == False - name: Remount a mounted volume ansible.posix.mount: @@ -73,3 +80,4 @@ src: "{{ dev }}p1" fstype: "{{ fstype }}" state: mounted + when: devpart2_exist.stat.islnk == False -- GitLab From b1b34d9849df4189e8b61e1c4ee9d05fd2469129 Mon Sep 17 00:00:00 2001 From: pullyvan <pullyvan.kris@gmail.com> Date: Tue, 1 Feb 2022 17:38:41 +0100 Subject: [PATCH 3/5] fix device not found by adding a check if device exists and destroy and recreate it if it does --- tasks/ubuntu2004.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/ubuntu2004.yml b/tasks/ubuntu2004.yml index 8031fce..06abc0b 100644 --- a/tasks/ubuntu2004.yml +++ b/tasks/ubuntu2004.yml @@ -26,7 +26,7 @@ - name: "Check if {{ devpart }} exists" stat: - path: "{{ dev }}" + path: "{{ devpart }}" register: devpart_exist - name: "Unmount a {{ mount }} mounted volume" @@ -42,7 +42,7 @@ state: absent fs_type: "{{ fstype }}" label: gpt - when: devpart_exist.stat.islnk is defined + when: device_exist.stat.islnk is defined - name: "Check if {{ devpart }} exists" stat: -- GitLab From d307e416361cbc47b0ecd931438ec1442841f2c4 Mon Sep 17 00:00:00 2001 From: pullyvan <pullyvan.kris@gmail.com> Date: Wed, 2 Feb 2022 09:38:22 +0100 Subject: [PATCH 4/5] fix device not found by adding a check if device exists and destroy and recreate it if it does --- defaults/main.yml | 4 ++-- tasks/debian.yml | 47 -------------------------------------------- tasks/ubuntu2004.yml | 4 +++- 3 files changed, 5 insertions(+), 50 deletions(-) delete mode 100644 tasks/debian.yml diff --git a/defaults/main.yml b/defaults/main.yml index 03830c4..9fbcf8c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,7 +2,7 @@ # defaults file for mount_hdd2 fstype: ext4 dev: /dev/nvme0n1 +devpart: nvme0n1p1 mount: /home opts: "rw" -state: mounted -devpart: nvme0n1p1 \ No newline at end of file +state: mounted \ No newline at end of file diff --git a/tasks/debian.yml b/tasks/debian.yml deleted file mode 100644 index e56c892..0000000 --- a/tasks/debian.yml +++ /dev/null @@ -1,47 +0,0 @@ ---- -# tasks file for mount_hdd2 - -- name: "Check if {{ dev }} exists" - stat: - path: "{{ dev }}" - -- name: Unmount a mounted volume - ansible.posix.mount: - path: "{{ mount }}" - state: unmounted - ignore_errors: yes - - -- name: Unmount a mounted folder - ansible.posix.mount: - path: "{{ mount }}" - state: unmounted - ignore_errors: yes - -- name: Create a new partition on disk - community.general.parted: - device: "{{ dev }}" - number: 1 - state: present - fs_type: "{{ fstype }}" - label: gpt - -- name: Create a filesystem on device - community.general.filesystem: - fstype: "{{ fstype }}" - dev: "{{ dev }}p1" - force: yes - -- name: Mount up device on folder in fstab - mount: - path: "{{ mount }}" - src: "{{ dev }}p1" - fstype: "{{ fstype }}" - state: present - -- name: Remount a mounted volume - ansible.posix.mount: - path: "{{ mount }}" - src: "{{ dev }}p1" - fstype: "{{ fstype }}" - state: mounted diff --git a/tasks/ubuntu2004.yml b/tasks/ubuntu2004.yml index f0fe40f..fc76ece 100644 --- a/tasks/ubuntu2004.yml +++ b/tasks/ubuntu2004.yml @@ -67,7 +67,6 @@ label: gpt when: devpart2_exist.stat.islnk == False - - name: Create a filesystem on device community.general.filesystem: fstype: "{{ fstype }}" @@ -90,3 +89,6 @@ fstype: "{{ fstype }}" state: mounted when: devpart2_exist.stat.islnk == False + + + -- GitLab From d508fb6165553450246fecca8f62425c9d75f159 Mon Sep 17 00:00:00 2001 From: pullyvan <pullyvan.kris@gmail.com> Date: Wed, 2 Feb 2022 09:43:08 +0100 Subject: [PATCH 5/5] fix device not found by adding a check if device exists and destroy and recreate it if it does2 --- tasks/ubuntu2004.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tasks/ubuntu2004.yml b/tasks/ubuntu2004.yml index fc76ece..e19706f 100644 --- a/tasks/ubuntu2004.yml +++ b/tasks/ubuntu2004.yml @@ -49,14 +49,6 @@ path: "{{ dev }}" register: devpart2_exist -- name: Make nvme visible on /dev/ - community.general.parted: - device: "{{ dev }}" - number: 1 - state: present - fs_type: "{{ fstype }}" - label: gpt - ignore_errors: yes - name: Create a new partition on disk community.general.parted: -- GitLab