Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AnsibleではじめるWindows自動化

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

 AnsibleではじめるWindows自動化

Interact 2018でお話ししたAnsibleによるWindows自動化のセッション資料です。

Avatar for hiyokotaisa

hiyokotaisa

June 30, 2018
Tweet

More Decks by hiyokotaisa

Other Decks in Technology

Transcript

  1. Interact 2018 10 Ansibleとは? Red Hatとコミュニティで開発している構成管理ツール • 最新版はAnsible 2.6 (2018/6/29

    リリース) • コミュニティ版とRed HatがサポートするAnsible Engine • 自動化オーケストレーションツールのAnsible Tower
  2. Interact 2018 11 Ansibleの利点 • 学習コストの低いYAML形式のPlaybook • べき等性を保った変更 • シンプルかつ柔軟な拡張が可能

    • コミュニティでの開発・拡張が活発 • 多種多様な環境をコントロール(Linux/Windows/Network機器)
  3. Interact 2018 12 Ansible Playbookのサンプル --- - name: Add a

    user hosts: all gather_facts: false tasks: - name: Add User win_user: name: ansible password: "@ns1bl3" state: present https://github.com/ansible/ansible-examples/blob/master/windows/create-user.yml
  4. Interact 2018 14 Ansibleの構造 Inventory host_A host_B Playbook test.yml 1.

    スクリプトを転送 host_A 3.結果を返却 Connection Plugin Modules 2.実行
  5. Interact 2018 18 事前準備 ▪ Ansible側 • pywinrmのパッケージの導入 Playbookには…… •

    ansible_connection: winrm を指定 • ansible_winrm_transportを指定
  6. Interact 2018 20 Windows Serverを管理する ▪ Windows側 • Powershell 3.0以上

    ( Windows 7 SP1 / Windows Server 2008 SP1以上 ) • WinRM(Windows Remote Management)の有効化 • 自動でWindowsホストで必要な準備を実行するPowershellも (ConfigureRemotingForAnsible.ps1) https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotin gForAnsible.ps1
  7. Interact 2018 22 便利なWindows Module • win_domain_user Active Directoryのユーザを管理 win_domain_user:

    name: bob firstname: Bob surname: Smith password: B0bP4ssw0rd state: present domain_username: DOMAIN\admin-account domain_password: SomePas2w0rd domain_server: [email protected]
  8. Interact 2018 23 便利なWindows Module • win_package パッケージのインストール/アンインストール • ネットワーク上のパッケージも取得可能

    win_package: path: http://download.microsoft.com/.../vcredist_x64.exe product_id: '{CF2BEA3C-26EA-32F8-AA9B-331F7E34BA97}' arguments: /install /passive /norestart
  9. Interact 2018 24 便利なWindows Module • win_updates Windows Updateの実行 -

    name: Install only particular updates based on the KB numbers win_updates: category_name: - SecurityUpdates whitelist: - KB4056892 - KB4073117
  10. Interact 2018 27 WinRMのトラブルシューティング ▪ WinRMの設定の問題か切り分ける • 他のWindowsマシンからWinRM接続を試してみる # test

    out HTTP winrs -r:http://server:5985/wsman -u:Username -p:Password ipconfig # test out HTTPS (will fail if the cert is not verifiable) winrs -r:http://server:5985/wsman -u:Username -p:Password -ssl ipconfig
  11. Interact 2018 31 事例: HTTP 401/Credentials Rejected • HTTP 401

    エラーの場合、接続時の認証で失敗している • 認証情報が正しいか • ユーザがlocal Administrator groupに属するユーザであること • ansible_winrm_transport で指定した認証方法が、 Service\Auth\下でEnableになっていること • Basic認証をADのユーザーに対して指定していないか • 関連するpythonパッケージを更新
  12. Interact 2018 33 事例: Timeout • FirewallがWinRMのListenerポートをブロックしていないか • WinRMサービスが起動しているか •

    ネットワークで問題が発生していないか • 負荷の高いタスクで発生する場合、Timeout値を伸ばしてみる ansible_winrm_operation_timeout_sec ansible_winrm_read_timeout_sec