-
Notifications
You must be signed in to change notification settings - Fork 4
/
windows_iot_config.yml
166 lines (139 loc) · 5.48 KB
/
windows_iot_config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
---
- name: windows iot configuration
hosts: windowsiot
become: false
gather_facts: true
strategy: free
vars:
azure:
service_principal_id: '3933c163-3dcc-4248-83fc-b1cbe2ee6865'
service_principal_secret: 'I8o8Q~F9Qn9tSY4LazVGDgZe1PBwmRsbVDlUubDd'
resource_group: 'AzureArcTest'
tenant_id: '76d4c62a-a9ca-4dc2-9187-e2cc4d9abe7f'
subscription_id: 'eb08cfa9-a0c3-4c8e-a834-b98dc83dd1e6'
location: 'eastus'
ansible_port: 5985
ansible_connection: winrm
ansible_winrm_transport: basic
ansible_winrm_server_cert_validation: ignore
ansible_password: Scale2010!
# ansible_user: user
tasks:
# - name: test ping
# ansible.windows.win_ping:
# - name: show ansible_os_family
# debug:
# msg: "{{ansible_os_family}}"
- name: Change the hostname to "{{ inventory_hostname }}"
ansible.windows.win_hostname:
name: "{{ inventory_hostname }}"
register: res
#reboot moved until later to avoid error
# - name: Reboot
# ansible.windows.win_reboot:
# reboot_timeout: 1800
# pre_reboot_delay: 10
# post_reboot_delay: 30
# when: res.reboot_required
# ignore_errors: true
# - name: Install all critical and security updates
# ansible.windows.win_updates:
# category_names:
# - CriticalUpdates
# - SecurityUpdates
# state: installed
# ignore_errors: true
# register: update_result
# - name: Reboot host if required
# win_reboot:
# when: update_result.reboot_required
# - name: Get whoami information
# ansible.windows.win_whoami:
# - name: Create local group to contain new users
# win_group:
# name: LocalGroup
# description: Allow access to C:\Development folder
# - name: Create local user
# win_user:
# name: '{{ item.name }}'
# password: '{{ item.password }}'
# groups: LocalGroup
# # update_password: false
# password_never_expires: true
# loop:
# - name: User1
# password: Password1
# - name: User2
# password: Password2
- name: Create iot data folder
win_file:
path: C:\iot
state: directory
- name: Set ACL of iot folder
win_acl:
path: C:\iot
rights: FullControl
state: present
type: allow
user: Everyone
- name: Add iot share
ansible.windows.win_share:
name: iot
description: iot data collection point
path: C:\iot
list: yes
full: Everyone
read: Everyone
# - name: Enable hyper-v optional feature
# ansible.windows.win_optional_feature:
# name: Microsoft-Hyper-V
# state: absent #note present will hang non vtpm based vms currently
# include_parent: true
# register: features
# - name: Reboot if managing features requires it
# ansible.windows.win_reboot:
# post_reboot_delay: 180
# pre_reboot_delay: 10
# when: features.reboot_required
# - name: Run an executable and send data to the stdin for the executable
# ansible.windows.win_command: powershell.exe -
# args:
# stdin: Write-Host test
# - name: Run AKSEdgeDeployment PowerShell script
# ansible.windows.win_powershell:
# script: |
# New-AksEdgeDeployment -JsonConfigFilePath C:\Users\user\Documents\AKS-Edge-main\tools\aksedge-config.json
# sits at a prompt with no force or silent option that I can find
- 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 on Windows
# win_command: azcmagent check -l "{{azure.location}}"
# 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: Check if the Connected Machine Agent has already been connected on Windows
win_command: azcmagent show #-j # -l "{{azure.location}}"
register: azcmagent_win_connected
when: ansible_os_family == 'Windows'
ignore_errors: yes
# failed_when: "'Disconnected' in azcmagent_win_connected.stdout"
failed_when: (azcmagent_win_connected.rc not in [ 0, 16 ])
changed_when: False
- name: Reboot host if required
win_reboot:
when: res.reboot_required
# - name: debug variable
# debug:
# var: azcmagent_win_connected
- name: Connect the Connected Machine Agent on Windows servers to Azure Arc
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 }}" --tags "Platform=HyperCore"'
when: "'Disconnected' in azcmagent_win_connected.stdout"