æ¦è¦
- Windowsã«å¯¾ãã¦Ansibleãå®è¡ããæ¹æ³ã«ã¤ãã¦è¨è¼ãã¾ã
Table of Contents
ç°å¢
Windowsã¸ã®æ¥ç¶è¦ä»¶ã確èªãã
ãµãã¼ã対象ã®Windowsãã¼ã¸ã§ã³ç¢ºèª
PowerShellã®ãã¼ã¸ã§ã³ç¢ºèª
- PowerShellã®ãã¼ã¸ã§ã³ã¯PowerShellã§ä¸è¨ã®ã³ãã³ããå®è¡ãããã¨ã§ç¢ºèªã§ãã¾ã
- ã¨ã©ã¼ãåºãå ´åã¯WinRMãµã¼ãã¹ãèµ·åãã¦ããªããã¨ãæ³å®ãããããã
Windows Remote Management
ãèµ·åãã¦ãããã確èªãã ãã
PS C:\Users\Administrator> winrm enumerate winrm/config/Listener
Listener
Address = *
Transport = HTTP
Port = 5985
Hostname
Enabled = true
URLPrefix = wsman
CertificateThumbprint
ListeningOn = 127.0.0.1, 192.168.48.138, ::1, fe80::902f:4d50:638f:38e%14
PS C:\Users\Administrator> $release = Get-ItemPropertyValue -LiteralPath 'HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -Name Release
PS C:\Users\Administrator> switch ($release) {
>> { $_ -ge 533320 } { $version = '4.8.1 or later'; break }
>> { $_ -ge 528040 } { $version = '4.8'; break }
>> { $_ -ge 461808 } { $version = '4.7.2'; break }
>> { $_ -ge 461308 } { $version = '4.7.1'; break }
>> { $_ -ge 460798 } { $version = '4.7'; break }
>> { $_ -ge 394802 } { $version = '4.6.2'; break }
>> { $_ -ge 394254 } { $version = '4.6.1'; break }
>> { $_ -ge 393295 } { $version = '4.6'; break }
>> { $_ -ge 379893 } { $version = '4.5.2'; break }
>> { $_ -ge 378675 } { $version = '4.5.1'; break }
>> { $_ -ge 378389 } { $version = '4.5'; break }
>> default { $version = $null; break }
>> }
PS C:\Users\Administrator>
PS C:\Users\Administrator> if ($version) {
>> Write-Host -Object ".NET Framework Version: $version"
>> } else {
>> Write-Host -Object '.NET Framework Version 4.5 or later is not detected.'
>> }
.NET Framework Version: 4.8
Ansibleã§Windowsã«æ¥ç¶
winrmã¢ã¸ã¥ã¼ã«ã®ã¤ã³ã¹ãã¼ã«
- Windowsã¸æ¥ç¶ããããã«Ansibleãµã¼ãã«
pywinrm
ã¢ã¸ã¥ã¼ã«ãå¿
è¦ã®ããã¤ã³ã¹ãã¼ã«ãã¾ã
pip install pywinrm
ã¤ã³ãã³ããªã®æºå
- Windowsã«æ¥ç¶ããããã®æ
å ±ãè¨è¼ããã¤ã³ãã³ããªãä½æ
---
all:
hosts:
Win2022:
ansible_host: 192.168.48.138
ansible_user: Administrator
ansible_password: P@ssword
ansible_connection: winrm
ansible_port: 5985
ansible_winrm_transport: ntlm
win10:
ansible_host: 192.168.48.139
ansible_user: hii
ansible_password: hii
ansible_connection: winrm
ansible_port: 5985
ansible_winrm_transport: ntlm
Playbookã®æºå
- Windowsã¸ã®æ¥ç¶ã確èªããããã®Playbookãä½æ
---
- name: Windows connection test
hosts: all
gather_facts: false
tasks:
- name: Ping
win_ping:
Playbookå®è¡
ansible-playbook -i inventory.yml main.yml
PLAY [Windows connection test] ***********************************************************************************************************************************************************************
TASK [Ping] ******************************************************************************************************************************************************************************************
ok: [Win2022]
ok: [win10]
PLAY RECAP *******************************************************************************************************************************************************************************************
Win2022 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
win10 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Windows 10ã¸å®è¡ããéã®ã¨ã©ã¼
- Windows 10ã«å¯¾ãã¦å®è¡ããéã«ä¸è¨ã®ã¨ã©ã¼ãåºåããã¾ãã
fatal: [win10]: UNREACHABLE! => {
"changed": false,
"msg": "ntlm: the specified credentials were rejected by the server",
"unreachable": true
}
ãããã«
- httpã§ã®æ¥ç¶ã§ããç¡äºæ¥ç¶ãããã¨ãã§ãã¾ããã
- httpsã§æ¥ç¶ããå ´åã¯è¨¼ææ¸ãæºåãããã¨æéã¯ãããã¾ããããå®å
¨ã«æ¥ç¶ãããã¨ãã§ããã®ã§è¦ä»¶ã«åããã¦å®æ½ãã¦ã¿ã¦ãã ãã
ãªã³ã¯