diff --git a/defaults/main.yml b/defaults/main.yml index 22ca5fe7ff0ddb3e98be7656a8e5ca10079a9a0e..9fbcf8caadecf13398e7847c5624f87999fed398 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,6 +2,7 @@ # defaults file for mount_hdd2 fstype: ext4 dev: /dev/nvme0n1 +devpart: nvme0n1p1 mount: /home opts: "rw" -state: mounted +state: mounted \ No newline at end of file diff --git a/tasks/debian.yml b/tasks/debian.yml deleted file mode 100644 index e56c892d7544047e695ec67b1a6a32f323a549c9..0000000000000000000000000000000000000000 --- 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 48c230ad096db4b6550bfc1ba2e49221924d161d..e19706f0ab841049dd7b2702883d54ebeab9468f 100644 --- a/tasks/ubuntu2004.yml +++ b/tasks/ubuntu2004.yml @@ -22,28 +22,33 @@ - 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: "{{ devpart }}" + 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: device_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 +57,14 @@ 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,7 @@ src: "{{ dev }}p1" fstype: "{{ fstype }}" state: mounted + when: devpart2_exist.stat.islnk == False + + +