Ansible and parted

From MyWiki
Revision as of 18:33, 23 March 2020 by George2 (Talk | contribs)

Jump to: navigation, search

https://docs.ansible.com/ansible/latest/modules/parted_module.html
logical volumes - https://docs.ansible.com/ansible/latest/modules/lvol_module.html

- name: Create a new primary partition
  parted:
    device: /dev/sdb
    number: 1
    state: present

- name: Remove partition number 1
  parted:
    device: /dev/sdb
    number: 1
    state: absent

- name: Create a new primary partition with a size of 1GiB
  parted:
    device: /dev/sdb
    number: 1
    state: present
    part_end: 1GiB

- name: Create a new primary partition for LVM
  parted:
    device: /dev/sdb
    number: 2
    flags: [ lvm ]
    state: present
    part_start: 1GiB
 
# Example on how to read info and reuse it in subsequent task
- name: Read device information (always use unit when probing)
  parted: device=/dev/sdb unit=MiB
  register: sdb_info

- name: Remove all partitions from disk
  parted:
    device: /dev/sdb
    number: '{{ item.num }}'
    state: absent
  loop: '{{ sdb_info.partitions }}'