Welcome to the Ansible section of our repository! Here you'll find all the information you need to configure your Azure dynamic inventory, utilize two roles (azure_vm_ufw
and nginx_webserver
), and even set up your local development environment using the provided example .env
file.
This document already assumes that ansible ,python3 and pip3 are installed by now.
The azure_vm_ufw
role is designed to manage the Uncomplicated Firewall (UFW) on Azure virtual machines. This role ensures that the required ports are open and rules are set according to your specifications.
The nginx_webserver
role sets up an Nginx web server on Azure virtual machines. It installs Nginx, configures it to serve static content, and manages the service.
We've configured Ansible to use the Azure dynamic inventory plugin, which enables dynamic inventory management of Azure resources. This means you don't need to maintain an inventory file manually. Instead, Ansible fetches real-time inventory directly from your Azure account.
To use the Azure dynamic inventory, ensure you have the Azure CLI installed and authenticated. Ansible will utilize your Azure credentials to fetch the inventory.
- Ansible version >=
2.9
- ansible-galaxy Collection
azure.azcollection
Use the below commands to install the requirements.
$ pip3 install msrest -I
$ ansible-galaxy collection install azure.azcollection
$ pip3 install -r ~/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt
Refer to the Ansible azcollection documentation for more information.
We've included an example.env
file to help you set up your local development environment. This file contains environment variables required to authenticate with Azure and configure Ansible. Please refer to the example.env file in this directory for details on required variables and their descriptions.
Before you begin, copy the example.env
file to .env
and fill in the appropriate values for your environment. Make sure to keep sensitive information like Azure credentials secure.
Click to view details of `example.env` file.
#!/usr/bin/env bash
## Ansible Env Vars:
## https://docs.ansible.com/ansible/latest/scenario_guides/guide_azure.html
## https://learn.microsoft.com/en-us/azure/developer/ansible/install-on-linux-vm?tabs=azure-cli#create-azure-credentials
export AZURE_CLIENT_ID="" ## Azure client ID
export AZURE_SECRET="" ## Azure client secret ID
export AZURE_TENANT="" ## Azure tenant ID
export AZURE_SUBSCRIPTION_ID="" ## Azure subscription ID
- Load your
*.env
file to terminal session
## In case you are creating your own *.env file, use below command else ignore
$ chmod +x <your-env-file-name>.env
## This is required to load your env vars, make sure you are in ansible directory
./example.env ## or ## ./<your-env-file-name>.env
Add
*.env
in your.gitignore
to avoid commiting secrets to Version control.
$ ansible-playbook set-up-ubuntu-nginx-webserver.yaml -i my.azure_rm.yaml --private-key <path-to-your-private-key>