Azure managed data disk can't be partitioned with ansible parted

415 Views Asked by At

I get the below error while trying to partition a managed azure disk that has been attached to a VM

TASK [role_azure_disk : Partition Azure Disk] ***********************************************************************************************************************************************************************************************
task path: /etc/ansible/roles/role_azure_disk/tasks/main.yml:7
fatal: [labserver]: FAILED! => {"changed": false, "err": "Error: Could not stat device /dev/sdc - No such file or directory.\n", "msg": "Error while getting device information with parted script: '/sbin/parted -s -m /dev/sdc -- unit 'KiB' print'", "out": "", "rc": 1}

The task is a simple task shown below:

- name: Partition Azure Disk
  parted:
    device: /dev/sdc
    number: 1
    state: present
  when: provider == "azure"

The device has no label as reported by parted (below) but can be formatted manually using fdisk.

Error: /dev/sdc: unrecognised disk label Model: Msft Virtual Disk (scsi) Disk /dev/sdc: 18.3GB Sector size (logical/physical): 512B/4096B Partition Table: unknown Disk Flags:

Not sure if this is an issue with parted or I'm doing this wrong?

I'm trying to avoid using fdisk passed to the shell module i.e.

(echo n; echo p; echo 1; echo ; echo ; echo w) | sudo fdisk /dev/sdc

Thanks

1

There are 1 best solutions below

0
On

Can you add your ansible tasks for creating the managed disk? We use this exact same parted call to partition managed disks all the time. Your ansible output indicates the disk isn't visible at the time you are trying to partition. My guess is your ansible tasks are running before the disk is actually present, and when you login later to manually fdisk it's there at that point.