/
Windows 에 Ansible 설치하기

Windows 에 Ansible 설치하기

It Automation 도구인 앤서블은 Linux 뿐만 아니라 Windows 에서도 사용할 수 있으며 많은 playbook 들이 이식되어 있습니다.


설치

사전 요구 사항

ansible 을 사용하려면 .NET 4.0 이상과 Power Shell 3.0 이상이 필요하며 Windows 10 이라면 기본 설정되어 있습니다.

Windows 7 이나 Windows Server 2008 을 사용한다면 ansible windows_setup 에서 upgrade script 를 받아서 설치해주면 됩니다.


WinRM 활성화

이제 WinRM(Windows Remote Management) 서비스를 활성화해야 합니다.


powershell 을 관리자로 실행한 후에 다음 명령어를 실행합니다.

$url = "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1"
$file = "$env:temp\ConfigureRemotingForAnsible.ps1"

(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)

powershell.exe -ExecutionPolicy ByPass -File $file


WinRM listener 이 잘 떠 있는지 확인합니다.

winrm enumerate winrm/config/Listener
Listener
    Address = *
    Transport = HTTP
    Port = 5985
    Hostname
    Enabled = true
    URLPrefix = wsman
    CertificateThumbprint
    ListeningOn = 127.0.0.1, 172.22.96.1, 192.168.137.1, ::1, fe80::5cd8:d34f:558e:71fd%2, fe80::7d9e:47fd:8858:3ca3%11, fe80::a059:ec0a:24c1:6967%28

Listener
    Address = *
    Transport = HTTPS
    Port = 5986
    Hostname = LESSTIF-OFFICE
    Enabled = true
    URLPrefix = wsman
    CertificateThumbprint = BD73EA77988156287B9FD5CCBB1EF52215400236
    ListeningOn = 127.0.0.1, 172.22.96.1, 192.168.137.1, ::1, fe80::5cd8:d34f:558e:71fd%2, fe80::7d9e:47fd:8858:3ca3%11, fe80::a059:ec0a:24c1:6967%28


WinRM listener 를 설정하기 위해 다음 명령어를 실행합니다. CertificateThumbprint 항목은 위에서 Listener 정보에 표시되는 정보로 교체해 주면 됩니다.


$selector_set = @{
Address = "*"
Transport = "HTTPS"
}
$value_set = @{
CertificateThumbprint = "BD73EA77988156287B9FD5CCBB1EF52215400236"
}

New-WSManInstance -ResourceURI "winrm/config/Listener" -SelectorSet $selector_set -ValueSet $value_set


Open SSH Server 설치

ansible 은 agent 가 없는 대신 SSH 로 연결해서 자동화하므로 SSH Server 를 설치해야 합니다. 

MS 는 Windows capability 를 통해 SSH Server 를 설치할 수 있도록 했지만 오래된 방법이라 ansible 이 제대로 동작하지 않으므로 다음 방법으로 설치해 주면 됩니다.


직접 다운로드

Win32-OpenSSH wiki에 연결해서 설치 스크립트를 실행해서 다운로드 받습니다.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$url = 'https://github.com/PowerShell/Win32-OpenSSH/releases/latest/'
$request = [System.Net.WebRequest]::Create($url)
$request.AllowAutoRedirect=$false
$response=$request.GetResponse()
$([String]$response.GetResponseHeader("Location")).Replace('tag','download') + '/OpenSSH-Win64.zip'  
$([String]$response.GetResponseHeader("Location")).Replace('tag','download') + '/OpenSSH-Win32.zip'


choco 사용

패키지 관리자인 choco 로 Open SSH Server 를 설치합니다.

choco install --package-parameters=/SSHServerFeature openssh


Ref

Related content

앤서블(ansible) 설치
앤서블(ansible) 설치
More like this
윈도우즈 터미널(Windows Terminal) 설정하기
윈도우즈 터미널(Windows Terminal) 설정하기
More like this
ansible playbook command line 주요 옵션
ansible playbook command line 주요 옵션
More like this
ansible yum module 사용법
ansible yum module 사용법
More like this
winget 으로 Windows terminal 에서 패키지 관리하기
winget 으로 Windows terminal 에서 패키지 관리하기
More like this
Windows 11 에서 WSLg( Windows Subsystem for Linux GUI ) 사용하기
Windows 11 에서 WSLg( Windows Subsystem for Linux GUI ) 사용하기
More like this