Skip to main content

Ansible Playbooks

Reference Azure

DOCUMENT CATEGORY: Reference SCOPE: Ansible automation for configuration management PURPOSE: Document Ansible playbooks used in Azure Local deployments MASTER REFERENCE: Ansible Documentation

Status: Active


Overview​

Ansible roles and playbooks for the on-premises steps of an Azure Local deployment: the domain controllers, Active Directory preparation, node OS configuration, Azure Arc registration, the monitoring agent, and the self-hosted CI/CD runners. They are an alternative route to the PowerShell scripts in scripts/deploy for the same tasks. Do not run both routes for the same step.

The values come from infrastructure.yml. The roles have no values of their own for the facts of an environment (names, addresses, domain, cloud, versions): config/variables/scripts/New-IacVariableFiles.ps1 writes the inventories and the variable files from the file, and the registry says, for every variable, which key it comes from. The toolkit test tests/variables/AnsibleValues.Tests.ps1 fails when a deployment value is written into the code.

The roles use Ansible Validated Content collections: microsoft.ad, ansible.windows, community.windows, and azure.azcollection.

Playbooks​

PlaybookDeployment PhaseTarget HostsDescription
05-management-vms.ymlPart 2, Phase 4domain_controllers (serial: 1)AD DS promotion of the domain controllers, DNS forwarders
01-ad-preparation.ymlPart 3, Phase 1domain_controllers[0]The OU and the LCM user (New-HciAdObjectsPreCreation), security groups, computer objects, Azure Arc conditional forwarders
02-os-configuration.ymlPart 4, Phase 3localhost (the controller)Runs Invoke-AzureLocalOsConfiguration.ps1 through the role azurelocal_os_configuration (src/ansible/roles/azurelocal_os_configuration)
03-arc-registration.ymlPart 4, Phase 4cluster_nodesArc endpoint validation, sign-in, Arc initialization
04-monitoring-setup.ymlPart 5, Phase 2cluster_nodesAzure Monitor Agent extension, the Azure Local Insights step
00-cicd-runner.ymlCI/CD setupthe generated inventory/cicd-runners.ymlConfigures an existing host as a self-hosted runner
site.ymlAllAll groupsMaster playbook: 05, 01, 02, 03, 04 in that order

Execution Order​

The domain controllers come first, because the AD preparation runs on the first of them:

# Run all phases in order (05, 01, 02, 03, 04). Phase 02 needs the infrastructure file itself.
ansible-playbook -i inventory/hosts.yml playbooks/site.yml -e @vault.yml \
-e azurelocal_os_configuration_infrastructure_file=./infrastructure.yml

# Or run individual phases
ansible-playbook -i inventory/hosts.yml playbooks/05-management-vms.yml
ansible-playbook -i inventory/hosts.yml playbooks/01-ad-preparation.yml
ansible-playbook playbooks/02-os-configuration.yml -e @/srv/azurelocal/os-configuration.yml # see "OS configuration" below
ansible-playbook -i inventory/hosts.yml playbooks/03-arc-registration.yml
ansible-playbook -i inventory/hosts.yml playbooks/04-monitoring-setup.yml

# Run specific tags
ansible-playbook -i inventory/hosts.yml playbooks/site.yml --tags ad-preparation

Windows Admin Center (wac-server) and the syslog receiver (syslog-receiver) are not run by any playbook: they are out of scope, kept in the repository and not run.

Roles​

domain-controller​

Promotes management VMs as domain controllers (playbook 05).

TaskModule UsedValues
Install AD-Domain-Services featureansible.windows.win_feature
Read the DSRM safe-mode password from Key Vaultazure.azcollection (on the controller)landing_zone.virtual_machines[].dsrm_password
Promote as new forest, or as a replicamicrosoft.ad.domain, microsoft.ad.domain_controllerlanding_zone.virtual_machines[].dc_promotion (new_forest or replica), identity.active_directory.forest_functional_level and domain_functional_level (WinThreshold or Win2025, default WinThreshold)
Configure the DNS forwardersansible.windows.win_powershellidentity.active_directory.dns_forwarders; when empty, Azure DNS for a VM in Azure only

ad-preparation​

Mirrors scripts/deploy/03-onprem-readiness/phase-01-active-directory/ (playbook 01).

TaskModule UsedValues
Read the LCM user's password from Key Vaultazure.azcollection (on the controller)identity.active_directory.lcm_user.password
Create the OU and the LCM userMicrosoft's New-HciAdObjectsPreCreationidentity.active_directory.ou_path, lcm_user.username
Create the security groups and add their membersmicrosoft.ad.groupidentity.active_directory.security_groups
Pre-create the computer objects of the nodes and of the clustermicrosoft.ad.computerprecreate_computer_objects
Create the conditional forwarders of the Azure Arc zones to Azure DNSansible.windows.win_powershellon a domain controller in Azure

No role generates a password: the LCM and DSRM passwords are the Key Vault secrets the deployment reads.

OS configuration​

Playbook 02 (src/ansible/playbooks/02-os-configuration.yml) runs the role azurelocal_os_configuration (src/ansible/roles/azurelocal_os_configuration) on the controller (localhost, connection: local). The role is the Ansible front end of scripts/deploy/04-cluster-deployment/phase-03-os-configuration/Invoke-AzureLocalOsConfiguration.ps1. The engine stays PowerShell 7: Ansible does not connect to the nodes. It starts pwsh, passes the wrapper its parameters, pauses for approval between Plan and Apply, shows report.json as facts and fails with the wrapper's exit code. The wrapper reads infrastructure.yml itself (domain join account, local administrators, join options, the management VLAN, the transport).

Pass the settings with a vars file. Copy src/ansible/vars/os-configuration.yml.example to a place outside the repository, set at least azurelocal_os_configuration_infrastructure_file, and run:

cd src/ansible
ansible-playbook playbooks/02-os-configuration.yml -e @/srv/azurelocal/os-configuration.yml --check # Plan only, changes nothing
ansible-playbook playbooks/02-os-configuration.yml -e @/srv/azurelocal/os-configuration.yml # Plan, pause for approval, Apply
  • Only the answer yes at the pause continues; anything else, or the timeout, fails the run with nothing changed. azurelocal_os_configuration_approved: true skips the pause on an unattended run.
  • --check is the Plan only.
  • In AWX, split the run into a workflow: a plan job, an approval node, then an apply job with azurelocal_os_configuration_phase: apply and azurelocal_os_configuration_approved: true.
  • The node credential (ISO-installed nodes over WinRM only) comes from Ansible Vault or the environment variables AZL_NODE_ADMIN_USER and AZL_NODE_ADMIN_PASSWORD. It reaches the wrapper only through the environment of one no_log task, never as a command line argument or a log line. For ZTP nodes the wrapper reads identity.local_admin from Key Vault.

The controller needs PowerShell 7 with powershell-yaml, Az.Accounts and Az.KeyVault, an Azure sign-in, and a checkout of the toolkit. The role's variables, the credential and AWX are in its README: src/ansible/roles/azurelocal_os_configuration/README.md.

There is one Ansible tree, src/ansible. The former top-level Ansible folder of the toolkit is gone, and so are its separate runner inventory and its stand-alone OS configuration play: playbook 02 is the only Ansible route to the OS configuration. See Automated OS configuration.

arc-registration​

Mirrors scripts/deploy/04-cluster-deployment/phase-04-arc-registration/.

TaskModule Used
Validate the Arc endpoints of the cloud (scenario.cloud)ansible.windows.win_powershell
Sign in and register the nodeansible.windows.win_powershell (Invoke-AzStackHciArcInitialization)
Verify Arc agent statusansible.windows.win_powershell (azcmagent show)

monitoring-agents​

Mirrors scripts/deploy/05-operational-foundations/phase-02-monitoring-observability/.

TaskModule Used
Install Azure Monitor Agent extensionansible.windows.win_powershell
Note the Azure Local Insights stepansible.windows.win_powershell

It creates no data collection rule: the rule Insights uses is the one the portal creates (operations.monitoring.data_collection_rule).

cicd_runner​

Configures an existing Linux or Windows host as a self-hosted runner for GitHub Actions, GitLab CI/CD or Azure Pipelines (playbooks/00-cicd-runner.yml with the generated inventory/cicd-runners.yml, from devops.runners[]; the account is devops.runners[].admin_username, default runneradmin).

wac-server and syslog-receiver​

Out of scope: kept in the repository, run by no playbook.

Required Collections​

CollectionVersionPurpose
azure.azcollection>= 2.4.0Azure resource management, Key Vault secrets
microsoft.ad>= 1.5.0Active Directory management
ansible.windows>= 2.3.0Core Windows modules
community.windows>= 2.2.0Extended Windows modules
community.general>= 9.0.0General utilities
ansible-galaxy collection install -r src/ansible/collections/requirements.yml

Inventory​

New-IacVariableFiles.ps1 (see Variables) writes the inventory from infrastructure.yml:

all:
children:
domain_controllers: # landing_zone.virtual_machines[] with role domain_controller
management: # the other landing_zone.virtual_machines[]
cluster_nodes: # nodes[]: host name nodes[].name
hosts:
iic-azl-n01:
ansible_host: 192.0.2.11 # nodes[].management.ip_address

cluster_nodes is the name of the Ansible host group. It is not a key of infrastructure.yml: the machines are listed in nodes[]. inventory/hosts.yml.example and inventory/cicd-runners.yml.example are the generator's output for the toolkit's example file.

Variables​

Variables are generated from the master infrastructure.yml:

./config/variables/scripts/New-IacVariableFiles.ps1 -InfrastructureFile ./infrastructure.yml -OutputDirectory D:\work\iac -Target Ansible

This writes inventory/hosts.yml, inventory/cicd-runners.yml, group_vars/ and host_vars/ (one per machine). Copy them into src/ansible/inventory/, where git ignores them. The group_vars/all.yml file in that folder is no longer committed: it is always generated (the toolkit keeps a copy for its tests under tests/variables/fixtures/ansible/inventory/). Every variable of the inventories, group_vars, host_vars and the role defaults is registered in the toolkit's registry (tools.ansible.variables) with the key it comes from. A secret is never written to these files.

Pass the secrets at run time with Ansible Vault:

ansible-vault create vault.yml
# domain_admin_password: the value behind identity.active_directory.domain_join_account.password (or lcm_user.password)
# spn_client_secret: the value behind devops.authentication.client_secret
ansible-playbook -i inventory/hosts.yml playbooks/site.yml -e @vault.yml

Repository​

Source: azurelocal-toolkit/src/ansible/


PreviousUpNext
Bicep TemplatesPart 3: Automation GuidesPowerShell Scripting Guide