Skip to content

Commit 402289a

Browse files
committed
draft of changes
1 parent 7dda03d commit 402289a

File tree

1 file changed

+73
-59
lines changed

1 file changed

+73
-59
lines changed

articles/azure-arc/servers/onboard-ansible-playbooks.md

Lines changed: 73 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -32,66 +32,80 @@ If you are onboarding machines to Azure Arc-enabled servers, copy the following
3232
```yaml
3333
---
3434
- name: Onboard Linux and Windows Servers to Azure Arc-enabled servers with public endpoint connectivity
35-
hosts: <INSERT-HOSTS>
36-
vars:
37-
azure:
38-
service_principal_id: 'INSERT-SERVICE-PRINCIPAL-CLIENT-ID'
39-
service_principal_secret: 'INSERT-SERVICE-PRINCIPAL-SECRET'
40-
resource_group: 'INSERT-RESOURCE-GROUP'
41-
tenant_id: 'INSERT-TENANT-ID'
42-
subscription_id: 'INSERT-SUBSCRIPTION-ID'
43-
location: 'INSERT-LOCATION'
35+
hosts: all
36+
# vars:
37+
# azure:
38+
# service_principal_id: 'INSERT-SERVICE-PRINCIPAL-CLIENT-ID'
39+
# service_principal_secret: 'INSERT-SERVICE-PRINCIPAL-SECRET'
40+
# resource_group: 'INSERT-RESOURCE-GROUP'
41+
# tenant_id: 'INSERT-TENANT-ID'
42+
# subscription_id: 'INSERT-SUBSCRIPTION-ID'
43+
# location: 'INSERT-LOCATION'
4444
tasks:
45-
- name: Check if the Connected Machine Agent has already been downloaded on Linux servers
46-
stat:
47-
path: /usr/bin/azcmagent
48-
get_attributes: False
49-
get_checksum: False
50-
get_mine: azcmagent_downloaded
51-
register: azcmagent_downloaded
52-
when: ansible_system == 'Linux'
53-
- name: Check if the Connected Machine Agent has already been downloaded on Windows servers
54-
stat:
55-
path: C:\Program Files\AzureConnectedMachineAgent
56-
get_attributes: False
57-
get_checksum: False
58-
get_mine: azcmagent_downloaded
59-
register: azcmagent_downloaded
60-
when: ansible_system == 'Windows'
61-
- name: Download the Connected Machine Agent on Linux servers
62-
become: yes
63-
get_url:
64-
url: https://aka.ms/azcmagent
65-
dest: ~/install_linux_azcmagent.sh
66-
mode: '700'
67-
when: (ansible_system == 'Linux') and (not azcmagent_downloaded.stat.exists)
68-
- name: Download the Connected Machine Agent on Windows servers
69-
win_get_url:
70-
url: https://aka.ms/AzureConnectedMachineAgent
71-
dest: C:\AzureConnectedMachineAgent.msi
72-
when: (ansible_os_family == 'Windows') and (not azcmagent_downloaded.stat.exists)
73-
- name: Install the Connected Machine Agent on Linux servers
74-
become: yes
75-
command:
76-
cmd: bash ~/install_linux_azcmagent.sh
77-
when: (ansible_system == 'Linux') and (not azcmagent_downloaded.stat.exists)
78-
- name: Install the Connected Machine Agent on Windows servers
79-
win_package:
80-
path: C:\AzureConnectedMachineAgent.msi
81-
when: (ansible_os_family == 'Windows') and (not azcmagent_downloaded.stat.exists)
82-
- name: Check if the Connected Machine Agent has already been connected
83-
become: true
84-
command:
85-
cmd: azcmagent show
86-
register: azcmagent_connected
87-
- name: Connect the Connected Machine Agent on Linux servers to Azure Arc
88-
become: yes
89-
command:
90-
cmd: 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 }}
91-
when: (azcmagent_connected.rc == 0) and (ansible_system == 'Linux')
92-
- name: Connect the Connected Machine Agent on Windows servers to Azure
93-
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 }}"'
94-
when: (azcmagent_connected.rc == 0) and (ansible_os_family == 'Windows')
45+
- name: Check if the Connected Machine Agent has already been downloaded on Linux servers
46+
stat:
47+
path: /usr/bin/azcmagent
48+
get_attributes: False
49+
get_checksum: False
50+
register: azcmagent_lnx_downloaded
51+
when: ansible_system == 'Linux'
52+
53+
- name: Download the Connected Machine Agent on Linux servers
54+
become: yes
55+
get_url:
56+
url: https://aka.ms/azcmagent
57+
dest: ~/install_linux_azcmagent.sh
58+
mode: '700'
59+
when: (ansible_system == 'Linux') and (azcmagent_lnx_downloaded.stat.exists == false)
60+
61+
- name: Install the Connected Machine Agent on Linux servers
62+
become: yes
63+
shell: bash ~/install_linux_azcmagent.sh
64+
when: (ansible_system == 'Linux') and (not azcmagent_lnx_downloaded.stat.exists)
65+
66+
- name: Check if the Connected Machine Agent has already been downloaded on Windows servers
67+
win_stat:
68+
path: C:\Program Files\AzureConnectedMachineAgent
69+
register: azcmagent_win_downloaded
70+
when: ansible_os_family == 'Windows'
71+
72+
- name: Download the Connected Machine Agent on Windows servers
73+
win_get_url:
74+
url: https://aka.ms/AzureConnectedMachineAgent
75+
dest: C:\AzureConnectedMachineAgent.msi
76+
when: (ansible_os_family == 'Windows') and (not azcmagent_win_downloaded.stat.exists)
77+
78+
- name: Install the Connected Machine Agent on Windows servers
79+
win_package:
80+
path: C:\AzureConnectedMachineAgent.msi
81+
when: (ansible_os_family == 'Windows') and (not azcmagent_win_downloaded.stat.exists)
82+
83+
- name: Check if the Connected Machine Agent has already been connected
84+
become: true
85+
command:
86+
cmd: azcmagent check
87+
register: azcmagent_lnx_connected
88+
ignore_errors: yes
89+
when: ansible_system == 'Linux'
90+
failed_when: (azcmagent_lnx_connected.rc not in [ 0, 16 ])
91+
changed_when: False
92+
93+
- name: Check if the Connected Machine Agent has already been connected on windows
94+
win_command: azcmagent check
95+
register: azcmagent_win_connected
96+
when: ansible_os_family == 'Windows'
97+
ignore_errors: yes
98+
failed_when: (azcmagent_win_connected.rc not in [ 0, 16 ])
99+
changed_when: False
100+
101+
- name: Connect the Connected Machine Agent on Linux servers to Azure Arc
102+
become: yes
103+
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 }}"
104+
when: (ansible_system == 'Linux') and (azcmagent_lnx_connected.rc is defined and azcmagent_lnx_connected.rc != 0)
105+
106+
- name: Connect the Connected Machine Agent on Windows servers to Azure
107+
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 }}"'
108+
when: (ansible_os_family == 'Windows') and (azcmagent_win_connected.rc is defined and azcmagent_win_connected.rc != 0)
95109
```
96110
97111
## Modify the Ansible playbook

0 commit comments

Comments
 (0)