diff --git a/defaults/main.yml b/defaults/main.yml index 22ca5fe7ff0ddb3e98be7656a8e5ca10079a9a0e..03830c4a9bbfb760697a51245427cc0d8ae58e77 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 48c230ad096db4b6550bfc1ba2e49221924d161d..dfd13ecefb4fbd5e663abf3fc31aa89b99509689 100644 --- a/tasks/ubuntu2004.yml +++ b/tasks/ubuntu2004.yml @@ -22,19 +22,32 @@ - name: "Check if {{ dev }} exists" stat: path: "{{ dev }}" + register: device_exist -- name: Unmount a mounted volume +- name: "Check if {{ devpart }} exists" + stat: + path: "{{ dev }}" + register: devpart_exist + +- name: "Unmount a {{ mount }} mounted volume" ansible.posix.mount: path: "{{ mount }}" state: unmounted ignore_errors: yes +- name: Delete a first partition on disk + community.general.parted: + device: "{{ dev }}" + number: 1 + state: absent + fs_type: "{{ fstype }}" + label: gpt + when: devpart_exist.stat.islnk is defined -- name: Unmount a mounted folder - ansible.posix.mount: - path: "{{ mount }}" - state: unmounted - ignore_errors: yes +- name: "Check if {{ devpart }} exists" + stat: + path: "{{ dev }}" + register: devpart2_exist - name: Make nvme visible on /dev/ community.general.parted: @@ -52,13 +65,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 +81,7 @@ src: "{{ dev }}p1" fstype: "{{ fstype }}" state: present + when: devpart2_exist.stat.islnk == False - name: Remount a mounted volume ansible.posix.mount: @@ -73,3 +89,4 @@ src: "{{ dev }}p1" fstype: "{{ fstype }}" state: mounted + when: devpart2_exist.stat.islnk == False