|
| 1 | +--- |
| 2 | +title: Connect machines at scale using Ansible Playbooks |
| 3 | +description: In this article, you learn how to connect machines to Azure using Azure Arc-enabled servers using Ansible playbooks. |
| 4 | +ms.date: 05/09/2022 |
| 5 | +ms.topic: conceptual |
| 6 | +ms.custom: template-how-to |
| 7 | +--- |
| 8 | + |
| 9 | +# Connect machines at scale using Ansible playbooks |
| 10 | + |
| 11 | +You can onboard Ansible-managed nodes to Azure Arc-enabled servers at scale using Ansible playbooks. To do so, you'll need to download, modify, and then run the appropriate playbook. |
| 12 | + |
| 13 | +Before you get started, be sure to review the [prerequisites](prerequisites.md) and verify that your subscription and resources meet the requirements. For information about supported regions and other related considerations, see [supported Azure regions](overview.md#supported-regions). Also review our [at-scale planning guide](plan-at-scale-deployment.md) to understand the design and deployment criteria, as well as our management and monitoring recommendations. |
| 14 | + |
| 15 | +If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin. |
| 16 | + |
| 17 | +## Generate a service principal and collect Azure details |
| 18 | + |
| 19 | +Before you can run the script to connect your machines, you'll need to do the following: |
| 20 | + |
| 21 | +1. Follow the steps to [create a service principal for onboarding at scale](onboard-service-principal.md#create-a-service-principal-for-onboarding-at-scale). |
| 22 | + |
| 23 | + * Assign the Azure Connected Machine Onboarding role to your service principal and limit the scope of the role to the target Azure subscription or resource group. |
| 24 | + * Make a note of the Service Principal Secret and Service Principal Client ID; you'll need these values later. |
| 25 | + |
| 26 | +1. Collect details on the Tenant ID, Subscription ID, Resource Group, and Region where the Azure Arc-enabled resource will be onboarded. |
| 27 | + |
| 28 | +## Download the Ansible playbook |
| 29 | + |
| 30 | +If you are onboarding machines to Azure Arc-enabled servers, copy the following Ansible playbook template and save the playbook as `arc-server-onboard-playbook.yml`. |
| 31 | + |
| 32 | +``` |
| 33 | +--- |
| 34 | +- name: Onboard Linux and Windows Servers to Azure Arc-enabled servers with public endpoint connectivity |
| 35 | + hosts: <INSERT-HOSTS> |
| 36 | + tasks: |
| 37 | + - name: Download the Connected Machine Agent on Linux servers |
| 38 | + become: yes |
| 39 | + get_url: |
| 40 | + url: https://aka.ms/azcmagent |
| 41 | + dest: ~/install_linux_azcmagent.sh |
| 42 | + mode: '700' |
| 43 | + when: ansible_system == 'Linux' |
| 44 | + - name: Download the Connected Machine Agent on Windows servers |
| 45 | + win_get_url: |
| 46 | + url: https://aka.ms/AzureConnectedMachineAgent |
| 47 | + dest: C:\AzureConnectedMachineAgent.msi |
| 48 | + when: ansible_os_family == 'Windows' |
| 49 | + - name: Install the Connected Machine Agent on Linux servers |
| 50 | + become: yes |
| 51 | + shell: bash ~/install_linux_azcmagent.sh |
| 52 | + when: ansible_system == 'Linux' |
| 53 | + - name: Install the Connected Machine Agent on Windows servers |
| 54 | + path: C:\AzureConnectedMachineAgent.msi |
| 55 | + when: ansible_os_family == 'Windows' |
| 56 | + - name: Connect the Connected Machine Agent on Linux servers to Azure Arc |
| 57 | + become: yes |
| 58 | + shell: sudo azcmagent connect --service-principal-id <INSERT-SERVICE-PRINCIPAL-CLIENT-ID> --service-principal-secret <INSERT-SERVICE-PRINCIPAL-SECRET> --resource-group <INSERT-RESOURCE-GROUP> --tenant-id <INSERT-TENANT-ID> --location <INSERT-REGION> --subscription-id <INSERT-SUBSCRIPTION-ID> |
| 59 | + when: ansible_system == 'Linux' |
| 60 | + - name: Connect the Connected Machine Agent on Windows servers to Azure |
| 61 | + win_shell: '& $env:ProgramFiles\AzureConnectedMachineAgent\azcmagent.exe connect --service-principal-id <INSERT-SERVICE-PRINCIPAL-CLIENT-ID> --service-principal-secret <INSERT-SERVICE-PRINCIPAL-SECRET> --resource-group <INSERT-RESOURCE-GROUP> --tenant-id <INSERT-TENANT-ID> --location <INSERT-REGION> --subscription-id <INSERT-SUBSCRIPTION-ID>' |
| 62 | + when: ansible_os_family == 'Windows' |
| 63 | +``` |
| 64 | + |
| 65 | +<!--If you are onboarding Linux servers to Azure Arc-enabled servers, download the following Ansible playbook template and save the playbook as `arc-server-onboard-playbook.yml`. |
| 66 | +
|
| 67 | +``` |
| 68 | +--- |
| 69 | +- name: Onboard Linux Server to Azure Arc-enabled servers with public endpoint |
| 70 | + hosts: <INSERT-HOSTS> |
| 71 | + tasks: |
| 72 | + - name: Download the Connected Machine Agent |
| 73 | + become: yes |
| 74 | + get_url: |
| 75 | + url: https://aka.ms/azcmagent |
| 76 | + dest: ~/install_linux_azcmagent.sh |
| 77 | + mode: '700' |
| 78 | + when: ansible_system == 'Linux' |
| 79 | + - name: Install the Connected Machine Agent |
| 80 | + become: yes |
| 81 | + shell: bash ~/install_linux_azcmagent.sh |
| 82 | + when: ansible_system == 'Linux' |
| 83 | + - name: Connect the Connected Machine Agent to Azure |
| 84 | + become: yes |
| 85 | + shell: sudo azcmagent connect --service-principal-id <INSERT-SERVICE-PRINCIPAL-CLIENT-ID> --service-principal-secret <INSERT-SERVICE-PRINCIPAL-SECRET> --resource-group <INSERT-RESOURCE-GROUP> --tenant-id <INSERT-TENANT-ID> --location <INSERT-REGION> --subscription-id <INSERT-SUBSCRIPTION-ID> |
| 86 | + when: ansible_system == 'Linux' |
| 87 | +```--> |
| 88 | + |
| 89 | +## Modify the Ansible playbook |
| 90 | + |
| 91 | +After downloading the Ansible playbook, complete the following steps: |
| 92 | + |
| 93 | +1. Within the Ansible playbook, modify the fields under the task **Connect the Connected Machine Agent to Azure** with the service principal and Azure details collected earlier: |
| 94 | + |
| 95 | + * Service Principal Id |
| 96 | + * Service Principal Secret |
| 97 | + * Resource Group |
| 98 | + * Tenant Id |
| 99 | + * Subscription Id |
| 100 | + * Region |
| 101 | + |
| 102 | +1. Enter the correct hosts field capturing the target servers for onboarding to Azure Arc. You can employ Ansible patterns to selectively target which hybrid machines to onboard. |
| 103 | + |
| 104 | +## Run the Ansible playbook |
| 105 | + |
| 106 | +From the Ansible control node, run the Ansible playbook by invoking the `ansible-playbook` command: |
| 107 | + |
| 108 | +``` |
| 109 | +ansible-playbook arc-server-onboard-playbook.yml |
| 110 | +``` |
| 111 | + |
| 112 | +After the playbook has run, the **PLAY RECAP** will indicate if all tasks were completed successfully and surface any nodes where tasks failed. |
| 113 | + |
| 114 | +## Verify the connection with Azure Arc |
| 115 | + |
| 116 | +After you have successfully installed the agent and configured it to connect to Azure Arc-enabled servers, go to the Azure portal to verify that the servers in your target hosts have successfully connected. View your machines in the [Azure portal](https://aka.ms/hybridmachineportal). |
| 117 | + |
| 118 | +## Next steps |
| 119 | + |
| 120 | +- Review the [Planning and deployment guide](plan-at-scale-deployment.md) to plan for deploying Azure Arc-enabled servers at any scale and implement centralized management and monitoring. |
| 121 | +- Review connection troubleshooting information in the [Troubleshoot Connected Machine agent guide](troubleshoot-agent-onboard.md). |
| 122 | +- Learn how to manage your machine using [Azure Policy](../../governance/policy/overview.md) for such things as VM [guest configuration](../../governance/policy/concepts/guest-configuration.md), verifying that the machine is reporting to the expected Log Analytics workspace, enabling monitoring with [VM insights](../../azure-monitor/vm/vminsights-enable-policy.md), and much more. |
| 123 | + |
0 commit comments