Mount disk on Azure Virtual Machine using Ansible

Hello guys , hope you are doing good. This is a very short but useful article on how to mount disk ( or a file system) on azure virtual machine using ansible.

Goal : Mount, format and add fstab entry in your Linux machine with this ansible role.


  • Disk already attached to the virtual machine

  • Machine is accessible through ssh

  • ansible already installed on the work system

  1. To clone the repository click here

  2. Create one playbook and enter host group where you want to mount azure disk like below. This is a really basic playbook that will just call our ansible role.

 # file: playbook.yml
 - hosts: target_hosts
 become: yes
  - azure_mount_disk

3. Execute the below command

 ansible-playbook -i inventory_file playbook.yml --ask-sudo-pass

Note - To disable host key checking do



It runs parted -l command to find out which new disk has been attached to the system and then formats it to xfs file system, make an entry in fstab to make the mount permanent.

This role can be used when you are spinning up instances and can embed this role in your existing playbooks by just including it.

Hope this helps :-)

292 views0 comments

Recent Posts

See All