diff --git a/tasks/centos.yml b/tasks/centos.yml new file mode 100644 index 0000000000000000000000000000000000000000..14792deeab6c5a3f96f35104ef6e9dc7b424db22 --- /dev/null +++ b/tasks/centos.yml @@ -0,0 +1,55 @@ +--- +# tasks file for mount_hdd2 + +- name: "Check if {{ dev }} exists" + stat: + path: "{{ dev }}" + register: hdd2 + +- name: install parted + become: yes + yum: + state: latest + pkg: + - parted.x86_64 + - parted-devel.x86_64 + +- name: Create a new partition on hdd2 + become: yes + parted: + name: home + part_type: primary + label: gpt + number: 1 + device: /dev/nvme0n1 + state: present + ignore_errors: yes + + + +- name: Get System Details + stat: path={{ dev }} + register: check_mount + when: hdd2.stat.exists == False + +- name: Check the type of filesystem if its data we need to format + shell: file -s {{ dev }} + register: fs + when: hdd2.stat.exists == False + +- name: setting facts + set_fact: + format_fs: true + when: "'{{ dev }}: data' in fs.stdout" + +- name: Format filesystem + filesystem: fstype={{ fstype }} dev={{ dev }} force=yes + +- name: Mount filesystem + mount: + fstype: "{{ fstype }}" + src: "{{ dev }}" + name: "{{ mount }}" + opts: "{{ opts }}" + state: "{{ state }}" + register: mount_info diff --git a/tasks/debian.yml b/tasks/debian.yml new file mode 100644 index 0000000000000000000000000000000000000000..42163be2ad4739ed3b13ce1c4d132fca1d80cf27 --- /dev/null +++ b/tasks/debian.yml @@ -0,0 +1,48 @@ +--- +# tasks file for mount_hdd2 + +- name: "Check if {{ dev }} exists" + stat: + path: "{{ dev }}" + register: hdd2 + +- name: Create a new partition on hdd2 + become: yes + parted: + name: home + part_type: primary + label: gpt + number: 1 + device: /dev/nvme0n1 + state: present + when: hdd2.stat.exists == False + +- name: Get System Details + stat: path={{ dev }} + register: check_mount + when: hdd2.stat.exists == False + +- name: Check the type of filesystem if its data we need to format + shell: file -s {{ dev }} + register: fs + when: hdd2.stat.exists == False + +- name: setting facts + set_fact: + format_fs: true + when: "'{{ dev }}: data' in fs.stdout" + +- name: Format filesystem + filesystem: fstype={{ fstype }} dev={{ dev }} force + when: format_fs is defined and format_fs == true and hdd2.stat.exists == False + +- name: Mount filesystem + mount: + fstype: "{{ fstype }}" + src: "{{ dev }}" + name: "{{ mount }}" + opts: "{{ opts }}" + state: "{{ state }}" + register: mount_info + + diff --git a/tasks/main.yml b/tasks/main.yml index df5d7164f73a782c4043d3932f563f1fe7902b99..ceeee8ddbae2dd4809c0f7b6d07f65da2e982375 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,46 +1,7 @@ --- # tasks file for mount_hdd2 +- include: debian.yml tags=debian + when: ansible_os_family == 'Debian' -- name: "Check if {{ dev }} exists" - stat: - path: "{{ dev }}" - register: hdd2 - -- name: Create a new partition on hdd2 - become: yes - parted: - name: home - part_type: primary - label: gpt - number: 1 - device: /dev/nvme0n1 - state: present - when: hdd2.stat.exists == False - -- name: Get System Details - stat: path={{ dev }} - register: check_mount - when: hdd2.stat.exists == False - -- name: Check the type of filesystem if its data we need to format - shell: file -s {{ dev }} - register: fs - when: hdd2.stat.exists == False - -- name: setting facts - set_fact: - format_fs: true - when: "'{{ dev }}: data' in fs.stdout" - -- name: Format filesystem - filesystem: fstype={{ fstype }} dev={{ dev }} - when: format_fs is defined and format_fs == true and hdd2.stat.exists == False - -- name: Mount filesystem - mount: - fstype: "{{ fstype }}" - src: "{{ dev }}" - name: "{{ mount }}" - opts: "{{ opts }}" - state: "{{ state }}" - register: mount_info +- include: centos.yml tags=centos + when: ansible_distribution == "CentOS" \ No newline at end of file