Need help with ansible-playbooks?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

160 Stars 259 Forks MIT License 135 Commits 10 Opened issues


Ansible Playbook Samples for Azure

Services available


Need anything else?

Contributors list

page_type: sample languages: - yaml products: - azure

description: "Examples and best practices for building Ansible Playbooks for Azure"

Travis CI

Ansible Playbooks for Azure

This repository contains examples and best practices for building Ansible Playbooks for Azure.


  • Azure Account. If you don't have one, get a free one.

To authenticate with Azure, generate service principal and expose them as environment variables or store them as a file.

  • Install Ansible
  • Install Azure dependencies package
  pip install ansible[azure]
  pip install -r ~/.ansible/roles/azure.azure_preview_modules/files/requirements-azure.txt

How to run

To run samples in your local environment,

  • git clone
  • cd ansible-playbooks
  • modify playbook to replace variables with yours, such as resource group name.
  • add Azure credential info by using one of the following options.

First option, set the following environment variables:


Second option, add the following content to the file


Third option, do a az login:

az login
  • ansible-playbook sample.yml

You also could develop your Ansible playbook and run it in Visual Studio Code.

Using Azure cloud shell in Visual Studio Code

Azure cloud shell automatically logs you in your azure subscription so you need not to do anything extra other than login to cluod shell and run the ansible-playbook command with -e switch to provide resourcegroupname variable value.

To be able to run Cloud Shell in Visual Studio Code, you will need to install Azure Account Extension in VS Code.

After installing the Azure Account extension, Login to cloud shell in VS code and clone this repository. Upload the Ansible Playbook you want to run to cloud drive and run the following command (replace

with your username value). Make sure you also replace the
playbook name
and corrosponding
variable name
expected by playbook.
ansible-playbook /home/yourusernameincloudshell/create_virtualmachine_with_subnet_in_different_resource_group.yml -e "resource_group_name=ansible_test_rg"

How to Contribute

Please refer to Coding Guideline on how to contribute.


Ansible on Azure

Get Started with Azure

Ansible Playbook

Ansible role azurepreviewmodules

Ansible Galaxy for example roles from the Ansible community for deploying many popular applications.


MIT License

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.


Sample playbooks in this repository are tested via travis CI, please see detail CI plan.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.