Ansible Playbook Samples for Azure
page_type: sample languages: - yaml products: - azure
This repository contains examples and best practices for building Ansible Playbooks for Azure.
To authenticate with Azure, generate service principal and expose them as environment variables or store them as a file.
pip install ansible[azure]
pip install -r ~/.ansible/roles/azure.azure_preview_modules/files/requirements-azure.txt
To run samples in your local environment,
git clone https://github.com/Azure-Samples/ansible-playbooks.git
First option, set the following environment variables:
AZURE_CLIENT_ID= AZURE_SECRET= AZURE_SUBSCRIPTION_ID= AZURE_TENANT=
Second option, add the following content to the file
[default] subscription_id=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx client_id=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx secret=xxxxxxxxxxxxxxxxx tenant=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Third option, do a az login:
You also could develop your Ansible playbook and run it 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
yourusernameincloudshellwith your username value). Make sure you also replace the
playbook nameand corrosponding
variable nameexpected by playbook.
ansible-playbook /home/yourusernameincloudshell/create_virtualmachine_with_subnet_in_different_resource_group.yml -e "resource_group_name=ansible_test_rg"
Please refer to Coding Guideline on how to contribute.
Ansible Galaxy for example roles from the Ansible community for deploying many popular applications.
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 https://cla.microsoft.com.
Sample playbooks in this repository are tested via travis CI, please see detail CI plan.