Nota
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
可以使用 Ansible playbook 大规模地将 Ansible 托管节点加入到已启用 Azure Arc 的服务器。 为此,需要下载、修改并运行相应的 playbook。
在开始之前,请务必查看先决条件,并验证你的订阅和资源是否符合要求。 有关支持的区域和其他相关注意事项的信息,请参阅支持的 Azure 区域。 另请查看我们的《大规模规划指南》,以了解设计和部署标准,以及我们的管理和监视建议。
如果没有 Azure 订阅,请在开始前创建一个试用版订阅。
生成服务主体并收集 Azure 详细信息
在运行脚本以连接计算机之前,需要执行以下操作:
按照步骤为大规模加入创建服务主体。
- 将 Azure Connected Machine 加入角色分配给服务主体,并将该角色的范围限定为目标 Azure 订阅或资源组。
- 请记下服务主体机密和服务主体客户端 ID,因为稍后需要使用这些值。
收集有关租户 ID、订阅 ID、资源组和区域(将在其中加入已启用 Azure Arc 的资源)的详细信息。
下载 Ansible playbook
如果要将计算机加入已启用 Azure Arc 的服务器,请复制以下 Ansible playbook 模板并将 playbook 另存为 arc-server-onboard-playbook.yml
。
---
- name: Onboard Linux and Windows Servers to Azure Arc-enabled servers with public endpoint connectivity
hosts: all
# vars:
# azure:
# 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'
# subscription_id: 'INSERT-SUBSCRIPTION-ID'
# location: 'INSERT-LOCATION'
tasks:
- name: Check if the Connected Machine Agent has already been downloaded on Linux servers
stat:
path: /usr/bin/azcmagent
get_attributes: False
get_checksum: False
register: azcmagent_lnx_downloaded
when: ansible_system == 'Linux'
- name: Download the Connected Machine Agent on Linux servers
become: yes
get_url:
url: https://aka.ms/azcmagent
dest: ~/install_linux_azcmagent.sh
mode: '700'
when: (ansible_system == 'Linux') and (azcmagent_lnx_downloaded.stat.exists == false)
- name: Install the Connected Machine Agent on Linux servers
become: yes
shell: bash ~/install_linux_azcmagent.sh
when: (ansible_system == 'Linux') and (not azcmagent_lnx_downloaded.stat.exists)
- name: Check if the Connected Machine Agent has already been downloaded on Windows servers
win_stat:
path: C:\Program Files\AzureConnectedMachineAgent
register: azcmagent_win_downloaded
when: ansible_os_family == 'Windows'
- name: Download the Connected Machine Agent on Windows servers
win_get_url:
url: https://aka.ms/AzureConnectedMachineAgent
dest: C:\AzureConnectedMachineAgent.msi
when: (ansible_os_family == 'Windows') and (not azcmagent_win_downloaded.stat.exists)
- name: Install the Connected Machine Agent on Windows servers
win_package:
path: C:\AzureConnectedMachineAgent.msi
when: (ansible_os_family == 'Windows') and (not azcmagent_win_downloaded.stat.exists)
- name: Check if the Connected Machine Agent has already been connected
become: true
command:
cmd: azcmagent check
register: azcmagent_lnx_connected
ignore_errors: yes
when: ansible_system == 'Linux'
failed_when: (azcmagent_lnx_connected.rc not in [ 0, 16 ])
changed_when: False
- name: Check if the Connected Machine Agent has already been connected on windows
win_command: azcmagent check
register: azcmagent_win_connected
when: ansible_os_family == 'Windows'
ignore_errors: yes
failed_when: (azcmagent_win_connected.rc not in [ 0, 16 ])
changed_when: False
- name: Connect the Connected Machine Agent on Linux servers to Azure Arc
become: yes
shell: azcmagent connect --service-principal-id "{{ azure.service_principal_id }}" --service-principal-secret "{{ azure.service_principal_secret }}" --resource-group "{{ azure.resource_group }}" --tenant-id "{{ azure.tenant_id }}" --location "{{ azure.location }}" --subscription-id "{{ azure.subscription_id }}"
when: (ansible_system == 'Linux') and (azcmagent_lnx_connected.rc is defined and azcmagent_lnx_connected.rc != 0)
- name: Connect the Connected Machine Agent on Windows servers to Azure
win_shell: '& $env:ProgramFiles\AzureConnectedMachineAgent\azcmagent.exe connect --service-principal-id "{{ azure.service_principal_id }}" --service-principal-secret "{{ azure.service_principal_secret }}" --resource-group "{{ azure.resource_group }}" --tenant-id "{{ azure.tenant_id }}" --location "{{ azure.location }}" --subscription-id "{{ azure.subscription_id }}"'
when: (ansible_os_family == 'Windows') and (azcmagent_win_connected.rc is defined and azcmagent_win_connected.rc != 0)
修改 Ansible playbook
下载 Ansible playbook 后,完成以下步骤:
在 Ansible playbook 中,使用前面收集的服务主体和 Azure 详细信息修改 vars 部分下的变量:
- 服务主体 ID
- 服务主体机密
- 资源组
- 租户 ID
- 订阅 ID
- 区域
输入正确的主机字段,捕获要加入到 Azure Arc 的目标服务器。可以使用 Ansible 模式以要加入的混合计算机为目标。
此模板将服务主体机密作为 Ansible playbook 中的变量传递。 请注意,Ansible 保管库可用于加密此机密,变量可以通过配置文件传递。
运行 Ansible playbook
在 Ansible 控制节点中,通过调用 ansible-playbook
命令运行 Ansible playbook:
ansible-playbook arc-server-onboard-playbook.yml
运行 playbook 后,PLAY RECAP 会指示是否已成功完成所有任务,并显示任务失败的节点。
验证是否与 Azure Arc 连接
成功安装代理并将其配置为连接到已启用 Azure Arc 的服务器后,请转到 Azure 门户,验证是否已成功连接目标主机中的服务器。 在 Azure 门户中查看计算机。
后续步骤
- 查看规划和部署指南,以便对按任意规模部署启用了 Azure Arc 的服务器进行规划,并实现集中管理和监视。
- 查看 Connected Machine Agent 故障排除指南中的连接故障排除信息。
- 了解如何使用 Azure Policy 管理计算机,例如,进行 VM 来宾配置、验证计算机是否向预期的 Log Analytics 工作区报告等等。