インフラエンジニアbacchiのわかったことまとめ

bacchi.me

Windows に Ansible Playbook を適用するための準備

Windows ホスト側の設定

ユーザー作成とパッケージの DL

1. admin権限持っているユーザーを作成する

2. c:\work を作成する

3. 上述2で作成したディレクトリで以下のファイルをダウンロードする

https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1

ダウンロードコマンドは以下です。

Invoke-WebRequest -Uri https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 -OutFile ConfigureRemotingForAnsible.ps1

WinRM のインストール

下記のコマンドを実行します。

powershell -ExecutionPolicy RemoteSigned .\ConfigureRemotingForAnsible.ps1

実行結果

PS C:\work> Invoke-WebRequest -Uri https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 -OutFile ConfigureRemotingForAnsible.ps1powershell
PS C:\work> powershell -ExecutionPolicy RemoteSigned .\ConfigureRemotingForAnsible.ps1
Self-signed SSL certificate generated; thumbprint: C0A9191D59E2E11E743B629BEEE5CD45E83BB87A
wxf : http://schemas.xmlsoap.org/ws/2004/09/transfer
a : http://schemas.xmlsoap.org/ws/2004/08/addressing
w : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
lang : ja-JP
Address : http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
ReferenceParameters : ReferenceParameters
OK

このコマンドを実施することで、以下が実行されます。

  • WinRM サービスの起動
  • Enable-PSRemoting (ネットワーク経由でのPowershellアクセス機能) の有効化
  • Firewall で WS-Management (WinRM HTTP , TCP 5985) の許可
  • Firewall で WS-Management (WinRM HTTPS , TCP 5985) の許可
  • 認証のオプションとしてCredSSP(Credential Security Support Provider)を有効化
  • Basic認証の無効化自己署名証明書 (Self-signed SSL certificate)の作成

Ansible 側の設定

inventory ファイルの編集

inventory ファイルに、対象の Win サーバを追記します。

疎通確認(Ansible PingPong のテスト)

win_ping モジュールで対象ホストと通信できるかどうか確認します。

ansible -i <inventory> IPアドレスorホスト名 -u <admin_user> -m win_ping -k
# -k: には、<admin_user> ユーザの PW を投入

実行結果(ここから) -----

$ ansible -i inventory winserver1 -u admin_user -m win_ping -k
winserver1 | SUCCESS => {
"changed": false,
"ping": "pong"
}

上記のように、 ping/pong が通ればOK!

  • B!