0

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

2 Answers 2

2

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.

-1

At Ansible 2.9

lvol will do lvcreate file will do mkdir filesystem for mkfs mount will handle mount

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.