Manage Azure with Ansible in 20 minutes
Prerequisites
- Azure subscription: Create a free account, here.
- Visual Studio Code: Download and install, here. (Windows, MacOS, and Linux)
Build the Ansible Dev Container
- Clone this repository
- Open Visual Studio Code
- Hit Ctrl+Shift+P (Windows) Command+Shift+P (MacOS) and run the command Remote-Containers: Open Folder in Container...
Create an Azure resource group
ansible localhost -m azure_rm_resourcegroup -a "name=ansible location=eastus"
Deploy the Azure Environment
ansible-playbook deploy_azure_env.yml -e 'password=<password>'
Replace <password>
with the desired VM's local admin password.
Test Azure VM connectivity
ansible-playbook ping.yml
ansible-playbook win-ping.yml
Secure passwords with ansible-vault
Use ansible-vault
to generate an encrypted string
echo -n '<Password>' | ansible-vault encrypt_string
Take the output from the previous command and update the ansible_password
value in group_var/linux
and group_var/windows
.
Run ansible-inventory
to validate the encrypted password
ansible-inventory -i inventory_azure_rm.yml --graph --ask-vault-pass
Configure the site webservers
Run the site.yml
playbook.
ansible-playbook site.yml -i inventory_azure_rm.yml --ask-vault-pass
Once complete, curl the Azure VMs public Ip addresses to confirm the web servers installation.
windowsPublicIp=$(az vm show -d -g demo-rg -n demo-win-vm --query publicIps -o tsv);
linuxPublicIp=$(az network public-ip show -g demo-rg -n demo-linux-pip --query 'ipAddress' -o tsv);
curl $windowsPublicIp;
curl $linuxPublicIp