title: Reliably targeting correct Azure Managed Disk on a Linux VM using an Ansible playbook
body: <p>How do I reliably partition and mount the file system of an Azure Managed Disk on a Linux VM using Ansible playbooks?</p>
  <p>I can create an Azure Managed Disk with <code>azure_rm_manageddisk</code> and assign it to a VM instance. My issue starts when I'm trying to take the disk into use. I just don't know how to reliably target the correct managed disk anymore for partitioning and file system mounting.</p>
  <p>Neither <code>azure_rm_manageddisk</code> nor <code>azure_rm_manageddisk_info</code> seems to return a reliable, unambigious id for the disk that could be referred from the OS side.</p>
  <p>I don't think the disk even shows up on <code>blkid</code> before it has been partitioned.</p>
  <p>Microsoft has documented that</p>
  <blockquote>
  <p>By default when you create a VM, Azure provides you with an OS disk (/dev/sda) and a temporary disk (/dev/sdb). All additional disks you add show up as /dev/sdc, /dev/sdd, /dev/sde and so on.</p>
  </blockquote>
  <p>(source: <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/linux/optimization" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/virtual-machines/linux/optimization</a>)</p>
  <p>but this doesn't seem reliable. I think I saw my VM have a setup different from this right after creation and this is definitely going to change after reboot. So no trusting <code>/dev/sdc</code> in my opinion. A rerun of a playbook could cause all kinds of havoc, if the block device files aren't stable. I actually managed already to make my root partition visible at <code>/media/my_data_disk_mount</code>.</p>
  <p>Is this just something I will have to handle manually? Seems odd. It's such a common thing to do.</p>
  <p>There's also <code>/dev/disk/azure/resource</code> for example, but that seemed to lead to messy results also.</p>
  <p>(source: <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/troubleshooting/troubleshoot-device-names-problems" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/virtual-machines/troubleshooting/troubleshoot-device-names-problems</a>)</p>
  <p>Maybe something with the LUN numbers?</p>