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

Interact 2019 -OP01: ひよこでもわかるAnsible AnsibleによるAzure構成管理

Interact 2019 -OP01: ひよこでもわかるAnsible AnsibleによるAzure構成管理

2019年6月29日に開催されたInteract 2019のスライド資料です。

hiyokotaisa

June 29, 2019
Tweet

More Decks by hiyokotaisa

Other Decks in Technology

Transcript

  1. 自己紹介 Agenda 2 八木澤 健人 (やぎさわ けんと) ITエンジニア 7年目 (昨年3月にTwitter転職しました)

    Ansible Engine / Ansible Tower のテクニカルサポートをしています @hiyoko_taisa https://github.com/hiyokotaisa
  2. 本日のおしながき Agenda 3 1. Ansibleのおさらい 2. Azureのおさらい 3. AnsibleからAzureを操作する 4.

    Dynamic Inventoryを活用してみる 5. Ansible Tower(AWX)からAzureを活用する
  3. Ansibleとは? What is Ansible 5 • Red Hatとコミュニティが開発している構成管理ツール • 学習コストの低いYAML形式のPlaybook

    • 冪等性(べきとうせい)を保った変更 • 多種多様な環境に対応 (Linux/Windows/Network/etc…) • エージェントレス • 最新バージョンは2.8.1
  4. Ansibleの動作イメージ What is Ansible 7 Inventory host_A host_B ... Playbook

    test.yml 1. スクリプトを転送 host_A 3.結果を返却 Connection Plugin Modules 2.実行
  5. Azureとは? What is Azure? 9 • Microsoftが提供するパブリッククラウドプラットフォーム • 100を超えるサービス ◦

    Azure Virtual Maches ◦ Azure SQL Database ◦ Azure Cosmos DB ◦ Azure Active Directory(Azure AD) ◦ etc...
  6. Azureを操作するとは? Managing Azure from Ansible 12 • Azure上のリソース管理 → azure_rm_*

    モジュール • Azure VM上のインスタンスに接続 → Dynamic Inventory
  7. 事前準備 Managing Azure from Ansible 15 • 実行するノードにAzure SDK Moduleをインストール

    https://docs.ansible.com/ansible/latest/scenario_guides/guide_azure.html ※ Azure Cloud ShellからもAnsibleを実行できる Azure Cloud Shell の概要 https://docs.microsoft.com/ja-jp/azure/cloud-shell/overview $ pip install 'ansible[azure]'
  8. Task内のパラメーターに定義する Agenda 27 - name: Power Off azure_rm_virtualmachine: resource_group: myResourceGroup

    name: testvm002 started: no client_id: xxxxxx secret: xxxx subscription_id: xxxx tenant: xxxx
  9. azure_rm_securitygroup Agenda 34 • セキュリティグループを作成する azure_rm_securitygroup: resource_group: Testing name: secgroup001

    rules: - name: SSH protocol: Tcp destination_port_range: 22 access: Allow priority: 101 direction: Inbound
  10. azure_rm_networkinterface Agenda 35 • NICを作成する azure_rm_networkinterface: resource_group: Testing name: testnic001

    virtual_network: testvn001 subnet: subnet001 public_ip_name: publicip001 security_group: secgroup001
  11. azure_rm_virtualmachine Agenda 36 • VMの作成・削除・起動・停止などができる azure_rm_virtualmachine: resource_group: Testing name: testvm

    vm_size: Standard_D1_v2 admin_username: test ssh_password_enabled: false image: offer: CentOS publisher: OpenLogic sku: '7.6' version: latest
  12. Playbookをつくる Agenda 38 • createvm.yml --- - hosts: localhost vars:

    tasks: - name: Create storage account azure_rm_storageaccount: resource_group: Testing name: hiyokotest account_type: Standard_LRS - name: Create virtual network azure_rm_virtualnetwork: ...
  13. Dynamic Inventoryとは? What is Ansible 41 • インベントリ情報をAPIから動的に取得する • 実体はPythonスクリプト

    • AWS/Azure/vCenter/OpenStackなど https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html
  14. azure_rm.py What is Ansible 43 • Azure VM向けDynamic Inventory https://github.com/ansible/ansible/blob/devel/contrib/inventory/azure_rm.py

    • 設定ファイルは azure_rm.ini https://github.com/ansible/ansible/blob/devel/contrib/inventory/azure_rm.ini
  15. Ansible Towerとは? What is Ansible 46 • Red Hatが開発するAnsible用オーケストレーションツール •

    Web UIによる管理 • 権限管理(RBAC) • Git等のVCSとの統合 • ワークフローの作成
  16. AWXとは? What is Ansible 47 • Ansible Tower のアップストリームプロジェクト •

    最新の機能が導入され、安定したものがAnsible Towerへ • コンテナ環境必須 • エンタープライズな環境にはAnsible Towerがオススメ
  17. なにがうれしい? What is Ansible Tower? 48 • 認証情報やPlaybookを一元管理できる • 実行結果を一元管理できる

    • 強力な権限管理 • LDAPやSSOによるユーザー管理 • Splunk等へのexternal logging • virtualenvを使って複数のAnsibleバージョンを 共存させられる
  18. Ansible Lightbulb What is Ansible Tower? 51 • 各種教材やデモ用のリソース https://github.com/ansible/lightbulb

    Ansibleもくもく会でも同様の教材を使っています もくもく会にも遊びにきてください!
  19. CONFIDENTIAL Designator linkedin.com/company/red-hat youtube.com/user/RedHatVideos facebook.com/redhatinc twitter.com/RedHat Red Hat is the

    world’s leading provider of enterprise open source software solutions. Award-winning support, training, and consulting services make Red Hat a trusted adviser to the Fortune 500. Thank you 53
  20. Ansible 2.8 x Windows 55 Ansible 2.8で追加された新機能 • Connection PluginにSSHを指定可能

    (Experimental Support) • 新モジュール: ◦ win_user_profile ◦ win_partition ◦ win_psrepository
  21. Ansible 2.8 x Windows 57 従来: WinRMによる接続 • HTTPS/HTTPベースの独自プロトコル •

    ansible_connection: winrm を指定する • Remote Management Serviceの有効化などの事前設定が必要 WinRM(WS-Management) HTTPS / HTTP Windows
  22. Ansible 2.8 x Windows 58 SSHによる接続 • Linux/Unixなどで広く使われてきたプロトコル • WinRMと比較してオーバーヘッドが少ない

    • ansible_connection: ssh を指定する • Windows側にOpenSSHのインストールが必要 Win32-OpenSSH SSH Windows
  23. Ansible 2.8 x Windows 59 SSH接続手順 1. Win32-OpenSSHのインストール 参考: https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH

    2. sshd_configの設定変更 (必要に応じて) PATH: %programdata%\ssh\sshd_config 3. ansible_shell_type を指定 ( cmd | powershell ) Windows側のDefault Shell設定と一致している必要がある (デフォルトはcmd.exe) 注意事項: v7.9.0.0p1-Betaより以前のバージョンのOpenSSHは、 ansible_shell_type: powershell を指定できない。 (Windows Server 2019に同梱されているOpenSSHなど)
  24. Ansible 2.8 x Windows 64 参考資料 • Windows SSH Setup

    - Ansible https://docs.ansible.com/ansible/2.8/user_guide/windows_setup.html#windows-ssh-setup • Win32-OpenSSH https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH • Galaxy Role https://galaxy.ansible.com/jborean93/win_openssh