LoginSignup
6
6

More than 3 years have passed since last update.

AnsibleでVMwareのVMインベントリレポートを自動生成するPlaybookを作ってみた

Posted at

VMwareのVMインベントリ情報をvCenterからエクスポートする時に

  • ブラウザを起動
  • vCenterへアクセス
  • ログイン
  • クラスタやホストを選択
  • VMのエクスポートする情報を選択
  • VMの情報をエクスポート

とするのが面倒なのでAnsibleを使ってレポートを自動生成するPlaybookを作ってみました。

ansible-vmware-vm-inventory-report-generator

ansible-vmware-vm-inventory-report-generator

上記のリポジトリにあるPlaybookでは htmlcsv でVMインベントリ情報がエクスポート可能です。
対象は、vCenterが管理している全VMになります。

使い方

venv環境作成

ここでは、python3のvenvを作ります。

[root@206d9746e86c ~]# python3 -m venv venv
[root@206d9746e86c ~]# source venv/bin/activate
(venv) [root@206d9746e86c ~]#

リポジトリをクローン

ansible-vmware-vm-inventory-report-generatorをクローンします。

(venv) [root@206d9746e86c ~]# git clone https://github.com/sky-joker/ansible-vmware-vm-inventory-report-generator.git

必要なモジュールのインストール

必要なモジュールをインストールします。

(venv) [root@206d9746e86c ~]# cd ansible-vmware-vm-inventory-report-generator/
(venv) [root@206d9746e86c ansible-vmware-vm-inventory-report-generator]# pip install -r requirements.txt

Playbookの変数変更

以下の変数を環境に合わせて変更します。

(venv) [root@206d9746e86c ansible-vmware-vm-inventory-report-generator]# vi ansible-vmware-vm-inventory-generator.yml
(snip)
  vars:
    hostname: vCenter IP                       # vCenterのIPか名前解決のできるホスト名に変更してください
    username: administrator@vsphere.local      # vCenterにログインするユーザーに変更してください
    password: ログインパスワードに変更してください       # vCenterにログインするユーザーのパスワードに変更してください
    export_type: html                          # エクスポートするタイプ、htmlまたはcsvに変更してください
(snip)

Playbookの実行

Playbookの変数を変更したらPlaybookを実行します。

(venv) [root@206d9746e86c ansible-vmware-vm-inventory-report-generator]# ansible-playbook ansible-vmware-vm-inventory-generator.yml
 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


PLAY [VMware VM Inventory Generator] ********************************************************************************************************************************

TASK [Gather fact for all vm] ***************************************************************************************************************************************
ok: [localhost]

TASK [Gather facts for vm summary] **********************************************************************************************************************************
ok: [localhost] => (item=molecule01)
ok: [localhost] => (item=AD01)
ok: [localhost] => (item=awx)
(snip)

問題なく実行できたらレポートが生成されています。
htmlを指定した場合はhtml、csvを指定した場合はcsvが生成されます

(venv) [root@206d9746e86c ansible-vmware-vm-inventory-report-generator]# ls vmware_vm_inventory_report.*
vmware_vm_inventory_report.csv  vmware_vm_inventory_report.html

こんな感じでAnsibleを使うことで情報取得とレポート生成の自動化が出来ますね :)

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6