When I run this on the command line it works fine:
echo -e \"n\\np\\n1\\n\\n\\nw\" | sudo fdisk /dev/sdb
But in Ansible it does not want to ru
How to allocate all free space to a new partition and add it to LVM in Ansible
If you're using LVM, look into this!
If you want to use all the free space of the device, look into this!
Starting with a device /dev/sda
and an existing partition on /dev/sda1
in {{ volumeGroup }}
.
Use the following approach to create a partition /dev/sda2
in the free space of /dev/sda
and to subsequently add the new partition to the existing {{ volumeGroup }}
- name: "Create partitions on devices"
block:
- name: install parted
package:
name: parted
state: present
- name: "Read device information /dev/sda"
parted:
device: "/dev/sda"
unit: MiB
register: device_info
- name: "Add new partition /dev/sda2"
parted:
device: "/dev/sda"
number: "2"
part_type: primary
flags: [ lvm ]
state: present
part_end: "100%"
part_start: "{{ device_info.partitions[0].end + 1}}MiB"
- name: "Add device to exising volume group {{ volumeGroup }}."
lvg:
vg: "{{ volumeGroup }}"
pvs: "/dev/sda1,/dev/sda2"