You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Task is to create 3 Azure VM images for legacy application installed and configured by Ansible
Temporary virtual machine (used to capture image from):
Must be placed in pre-defined Azure VNet's Subnet (instead of temporary VNet and Subnet created by Packer by default)
Must have Private IP only (by default Packer creates Public IPs)
Must be set by Ansible (for demo purposes Ansible creates C:\build_config.txt) using variables from:
var1 from Azure DevOps Variable group ansible-build-common as regular variable
var2 from Azure DevOps Variable group ansible-build-common as secret variable
var3 from Azure DevOps Variable group ansible-build-vm* as regular variable
var4 from Azure DevOps Variable group ansible-build-vm* as secret variable
Production (resulting) virtual machine:
Must be placed in pre-defined Azure VNet's Subnet
Must have Private IP only
Must be set by Ansible (for demo purposes Ansible creates C:\deploy_config.txt) using variables from:
var1 from Azure DevOps Variable group ansible-deploy-common as regular variable
var2 from Azure DevOps Variable group ansible-deploy-common as secret variable
var3 from Azure DevOps Variable group ansible-deploy-vm* as regular variable
var4 from Azure DevOps Variable group ansible-deploy-vm* as secret variable
var5for VM2 and VM3 only: IP address of VM1 from Azure DevOps pipeline
var6for VM3 only: IP address of VM2 from Azure DevOps pipeline
Azure Resources
Challenges
Ansible variables
As you might noticed above ansible-build-common and ansible-deploy-common have the same variable names as required by legacy app
..and all VMs have the same variable names in ansible-deploy-vm1, ansible-deploy-vm2 and ansible-deploy-vm3
This issue is solved by linking Azure DevOps Variable groups to specific stages and jobs in pipeline instead of the whole pipeline's level
Issues with Packer
1. Azure DevOps Service Connection for Azure doesn't work with Packer
Solution is to use "Azure Active Directory Service Principal" which is less safe and convenient than Azure DevOps Service connection
2. Packer's Ansible connection plugin fails for Windows
Solution is to use Azure CLI to replace what Packer does, e.g. CReate VM, Setup WinRM, Run Ansible, Capture image, Terminate tmp resources
Azure DevOps pipeline
Production vs Pull request verification
Pipeline supports Pull requests verification (on Pull request to master branch) and VM image build and deploy (on commit to master branch)
Pull request verification (PRV) builds and deploys image to temporary environment:
If PRV verification is successful, code snapshot is marked as valid for merging and tmp environment is deleted
If PRV verification failed code snapshot is marked as invalid and tmp environment is not deleted for manual investigation
Agent and network
Azure DevOps agent must have access to the virtual network that is used for VM image build
Azure DevOps agents are executed in Docker kagarlickij/packer-ansible-azure-docker-runtime:3.1.0 runtime with preinstalled Packer, Ansible, Azure CLI and necessary Python packages
Azure DevOps agents can be started on VM on system startup: @reboot /root/ados-agents-start.sh in crontab -e ados-agents-start.sh script:
#!/bin/bash
for run in {1..5}
do
docker run -d -e VSTS_ACCOUNT='kagarlickij' -e VSTS_POOL='Self-Hosted-Containers' -e VSTS_TOKEN='a***q' kagarlickij/packer-ansible-azure-docker-runtime:3.1.0 > /dev/null 2>&1
done
Templates
Pipeline has some repeating steps which are moved to ./templates to avoid code duplication
Templates are not plugins so some pieces (e.g network settings) are "hardcoded"
Template types are Job (for deploy) and Step (for all other) not because of the most suitable kind but because templates can not be used as dependency for other jobs/stages/etc