Ansible Playbooks
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
| Playbook | Deployment Phase | Target Hosts | Description |
|---|---|---|---|
05-management-vms.yml | Part 2, Phase 4 | domain_controllers (serial: 1) | AD DS promotion of the domain controllers, DNS forwarders |
01-ad-preparation.yml | Part 3, Phase 1 | domain_controllers[0] | The OU and the LCM user (New-HciAdObjectsPreCreation), security groups, computer objects, Azure Arc conditional forwarders |
02-os-configuration.yml | Part 4, Phase 3 | localhost (the controller) | Runs Invoke-AzureLocalOsConfiguration.ps1 through the role azurelocal_os_configuration (src/ansible/roles/azurelocal_os_configuration) |
03-arc-registration.yml | Part 4, Phase 4 | cluster_nodes | Arc endpoint validation, sign-in, Arc initialization |
04-monitoring-setup.yml | Part 5, Phase 2 | cluster_nodes | Azure Monitor Agent extension, the Azure Local Insights step |
00-cicd-runner.yml | CI/CD setup | the generated inventory/cicd-runners.yml | Configures an existing host as a self-hosted runner |
site.yml | All | All groups | Master 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).
| Task | Module Used | Values |
|---|---|---|
| Install AD-Domain-Services feature | ansible.windows.win_feature | |
| Read the DSRM safe-mode password from Key Vault | azure.azcollection (on the controller) | landing_zone.virtual_machines[].dsrm_password |
| Promote as new forest, or as a replica | microsoft.ad.domain, microsoft.ad.domain_controller | landing_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 forwarders | ansible.windows.win_powershell | identity.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).
| Task | Module Used | Values |
|---|---|---|
| Read the LCM user's password from Key Vault | azure.azcollection (on the controller) | identity.active_directory.lcm_user.password |
| Create the OU and the LCM user | Microsoft's New-HciAdObjectsPreCreation | identity.active_directory.ou_path, lcm_user.username |
| Create the security groups and add their members | microsoft.ad.group | identity.active_directory.security_groups |
| Pre-create the computer objects of the nodes and of the cluster | microsoft.ad.computer | precreate_computer_objects |
| Create the conditional forwarders of the Azure Arc zones to Azure DNS | ansible.windows.win_powershell | on 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
yesat the pause continues; anything else, or the timeout, fails the run with nothing changed.azurelocal_os_configuration_approved: trueskips the pause on an unattended run. --checkis 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: applyandazurelocal_os_configuration_approved: true. - The node credential (ISO-installed nodes over WinRM only) comes from Ansible Vault or the environment variables
AZL_NODE_ADMIN_USERandAZL_NODE_ADMIN_PASSWORD. It reaches the wrapper only through the environment of oneno_logtask, never as a command line argument or a log line. For ZTP nodes the wrapper readsidentity.local_adminfrom 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/.
| Task | Module Used |
|---|---|
Validate the Arc endpoints of the cloud (scenario.cloud) | ansible.windows.win_powershell |
| Sign in and register the node | ansible.windows.win_powershell (Invoke-AzStackHciArcInitialization) |
| Verify Arc agent status | ansible.windows.win_powershell (azcmagent show) |
monitoring-agents
Mirrors scripts/deploy/05-operational-foundations/phase-02-monitoring-observability/.
| Task | Module Used |
|---|---|
| Install Azure Monitor Agent extension | ansible.windows.win_powershell |
| Note the Azure Local Insights step | ansible.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
| Collection | Version | Purpose |
|---|---|---|
azure.azcollection | >= 2.4.0 | Azure resource management, Key Vault secrets |
microsoft.ad | >= 1.5.0 | Active Directory management |
ansible.windows | >= 2.3.0 | Core Windows modules |
community.windows | >= 2.2.0 | Extended Windows modules |
community.general | >= 9.0.0 | General 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/
Navigation
| Previous | Up | Next |
|---|---|---|
| Bicep Templates | Part 3: Automation Guides | PowerShell Scripting Guide |