I need to run those commands, but I do not want to use 'shell', is there way to create home partition using ansible tools?
lvcreate -L5G -n home vg0
mkdir /home
mkfs.xfs /dev/mapper/vg0-home
mount /dev/mapper/vg0-home /home
Use the community.general.lvol module to manage logical volumes.
- name: Create a logical volume home with 5g
community.general.lvol:
vg: vg0
lv: home
size: 5g
Use ansible.builtin.file to create the directory.
- name: Create /home directory
ansible.builtin.file:
path: /home
state: directory
mode: '0755'
The community.general.filesystem module allows you to create filesystems.
- name: Create xfs filesystem on vg0-home
community.general.filesystem:
fstype: xfs
dev: /dev/mapper/vg0-home
Finally, ansible.posix.mount lets you mount what you created.
- name: Mount home volume
ansible.posix.mount:
path: /home
src: /dev/mapper/vg0-home
fstype: xfs
state: present
This can be generalized by introducing variables for the FS type, mount point, volume size, volume name and volume group name.
At Ansible 2.9
lvol will do lvcreate file will do mkdir filesystem for mkfs mount will handle mount