Automated deployment of nginx web servers behind an Azure Load Balancer.
Infrastructure is provisioned using Terraform, then the private machines are configured using Ansible through a jumpbox.
The workers only have private IP addresses. The jumpbox is the only virtual machine exposed for SSH access. The load balancer also provides outbound connectivity to the workers.
Clone the repo:
git clone https://github.com/pathei-kosmos/ansinetes.git
cd ansinetesInitialize the Terraform project:
terraform initStart by connecting Azure CLI to the Azure subscription you want to use for deployment:
az loginCopy the example variables file:
cp terraform.tfvars.example terraform.tfvarsThree variables need to be set:
subscription_id: ID of the Azure subscription to use for deployment.admin_cidr: public IPv4 CIDR allowed to connect to the jumpbox over SSH, for example203.0.113.10/32.admin_ssh_public_key: public SSH key used to connect to the virtual machines.
The syntax of the terraform.tfvars file is as follows:
subscription_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
admin_cidr = "203.0.113.10/32"
admin_ssh_public_key = "ssh-ed25519 AAAA..."You can then check the resources to be deployed:
terraform planIf everything looks fine, start the deployment:
terraform applyOnce the infrastructure is deployed, generate the Ansible inventory from the Terraform outputs:
terraform output -raw ansible_inventory > playbooks/inventory.iniThen configure the nginx workers:
ansible-playbook -i playbooks/inventory.ini playbooks/nginx.ymlAnsible connects to the private workers through the jumpbox using SSH ProxyJump.
If your SSH key is not automatically detected, specify it manually:
ansible-playbook -i playbooks/inventory.ini playbooks/nginx.yml --private-key ~/.ssh/id_ed25519The public IP address of the load balancer can be retrieved with:
terraform output -raw load_balancer_ipYou can then query the nginx servers:
curl "http://$(terraform output -raw load_balancer_ip)"Each worker serves a page containing its hostname.
To delete the deployed resources:
terraform destroy