EX294 · Question #19
19. Create partitions (randomly selected with Question 9: creating logical volumes) Choose either partitions or LVM to complete. On the balancers host, perform partitioning: (1) Create a new…
The task requires an Ansible playbook to create and configure partitions on /dev/vdb and /dev/vdc on the balancers host, including formatting as ext4 and mounting to specified directories, with dynamic size adjustments based on available space and an error check for a…
Question
- Create partitions (randomly selected with Question 9: creating logical volumes) Choose either partitions or LVM to complete. On the balancers host, perform partitioning: (1) Create a new partition on /dev/vdb, partition number 1, size 1500 MB, format it as ext4, and mount it to the /newpart1 directory. If there is not enough space, create a 800 MB partition instead. (Exam environment: /dev/vdb size is 2 GB.) (2) Create a new partition on /dev/vdc, partition number 1, size 1500 MB, format it as ext4, and mount it to the /newpart2 directory. If there is not enough space, create a 800 MB partition instead. (Exam environment: /dev/vdc size is 1 GB.) (3) If the volume group vdd does not exist, an error message should be displayed: Volume group vdd not exist Exam note: First check the target node to see which disk has enough space for 1500 MB, and perform that one first. For example, if /dev/vdc has enough space for 1500 MB, then the block of tasks should first partition /dev/vdc. Explanation/Reference: Solution: - name: partition hosts: balancers tasks: - name: Create a directory1 ansible.builtin.file: name: /newpart1 state: directory - name: Create a directory2 ansible.builtin.file: name: /newpart2 state: directory - block: - name: device vdc 1500M community.general.parted: device: /dev/vdc number: 1 state: present part_end: 1500MiB - name: ext4 vdc filesystem community.general.filesystem: fstype: ext4 dev: /dev/vdc1 ansible.posix.mount: path: /newpart2 src: /dev/vdc1 fstype: ext4 state: mounted - name: device vdb 1500M community.general.parted: device: /dev/vdb number: 1 state: present part_end: 1500MiB - name: ext4 vdb filesystem community.general.filesystem: fstype: ext4 dev: /dev/vdb1 - name: mount vdb ansible.posix.mount: path: /newpart1 src: /dev/vdb1 fstype: ext4 state: mounted rescue: - debug: msg: Could not create partation of that size - name: device vdb 800M community.general.parted: device: /dev/vdb number: 1 state: present part_end: 800MiB when: ansible_facts.devices.vdb is defined - name: ext4 vdb filesystem community.general.filesystem: fstype: ext4 dev: /dev/vdb1 when: ansible_facts.devices.vdb is defined - name: mount vdb ansible.posix.mount: path: /newpart1 src: /dev/vdb1 fstype: ext4 state: mounted when: ansible_facts.devices.vdb is defined - name: device vdc 800M community.general.parted: device: /dev/vdc number: 1 state: present part_end: 800MiB when: ansible_facts.devices.vdc is defined - name: ext4 vdc filesystem community.general.filesystem: fstype: ext4 dev: /dev/vdc1 when: ansible_facts.devices.vdc is defined - name: mount vdc ansible.posix.mount: path: /newpart2 src: /dev/vdc1 fstype: ext4 state: mounted when: ansible_facts.devices.vdd is undefined [greg@control ansible]$ ansible-navigator run partition.yml -m stdout
Explanation
The task requires an Ansible playbook to create and configure partitions on /dev/vdb and /dev/vdc on the balancers host, including formatting as ext4 and mounting to specified directories, with dynamic size adjustments based on available space and an error check for a non-existent volume group vdd.
Concept tested. Disk partitioning, filesystem creation, mounting, conditional logic
Reference. https://docs.ansible.com/ansible/latest/collections/community/general/parted_module.html
Topics
Community Discussion
No community discussion yet for this question.