joe-speedboat.fact_inventory
役割名
joe-speedboat.fact_inventory
説明
このAnsibleロールは、さまざまなエンドポイントリソースから重要な情報を収集することを可能にし、インフラストラクチャ管理に役立つ情報を提供します。仮想マシンをデプロイしたり、リソースの概要を作成したり、ネットワークトポロジーを視覚化したりする必要がある場合でも、このロールは異なるエンドポイントから情報を収集することでプロセスを簡素化します。
特徴
- リソース非依存: VMware vCenter、AWS、Azureなどさまざまなエンドポイントリソースに対応。
- 簡単な設定: YAML変数を使用して収集するリソースを指定する簡単な設定。
- 構造化データ: データセンター、クラスタ、ホスト、仮想マシン、データストア、ネットワークなどの構造化データを収集。
- JSON出力: 収集した情報を整形されたJSONファイルに生成し、さらに分析や視覚化に適した形式を提供。
要件
- Ansible >= 2.11
- Python >= 3.6(ターゲットホスト上)
- Pythonパッケージ:
- pip
- setuptools
- vsphere-automation-sdk-python
- Ansibleコレクション:
- community.vmware
ロール変数
以下の変数が設定可能です:
inventory_file: インベントリファイルのパス。デフォルトは/tmp/fact_inventory.json。debug_vars: デバッグモードを切り替えるためのブール値。デフォルトはTrue。inventory_targets: 情報を収集するターゲットのリスト。各ターゲットは次のキーを持つ辞書である必要があります:ressource_name: リソースの名前。type: リソースのタイプ(例: "vsphere")。validate_certs: 証明書の検証を切り替えるためのブール値。vcenter_api_url: vCenter APIのURL。vcenter_username: vCenter APIのユーザー名。vcenter_password: vCenter APIのパスワード。datacenter_regex: データセンターをフィルタするための正規表現。cluster_regex: クラスターをフィルタするための正規表現。host_regex: ホストをフィルタするための正規表現。datastore_regex: データストアをフィルタするための正規表現。network_regex: ネットワークをフィルタするための正規表現。vm_folder_regex: VMフォルダーをフィルタするための正規表現。
依存関係
なし。
ライセンス
GPLv3
使用方法
このロールを使用するには、プレイブック内のinventory_targetsリストに変数を指定する必要があります。リスト内の各アイテムは、情報を収集するターゲットを表します。
datacenter_regex、cluster_regex、host_regex、datastore_regex、network_regex、およびvm_folder_regex変数は、vSphere APIの結果をフィルタリングするために使用できます。これらの変数は正規表現を受け付けます。たとえば、名前が「dc」で始まるデータセンターのみから情報を収集したい場合、datacenter_regexを'^dc'に設定できます。
テスト
テストを実行する前に、testsディレクトリ内に特定の設定を含むvars.ymlファイルを作成する必要があります。これを行うには、vars_example.ymlファイルをコピーします:
cp tests/vars_example.yml tests/vars.yml
次に、フィルタリング用の正規表現を含む特定の値でvars.ymlファイルを埋めます。
テストを実行するには、次のコマンドを実行します:
ansible-playbook tests/test.yml -i tests/inventory
このコマンドは、testsディレクトリにあるインベントリファイルを使用して、test.ymlプレイブックを実行します。
Rundeckオプション用のCGIスクリプト
RundeckとJSONを使用すると、素晴らしいジョブメニューを作成できます。
ただし、そのためには最初にCGIサーバーをセットアップし、このロールによって作成されたJSONリソースファイルを使用する必要があります。
以下は、Rocky Linux 8でlighttpdとCGIを設定する方法です:
dnf install lighttpd
systemctl enable lighttpd
cp -av /etc/lighttpd/modules.conf /etc/lighttpd/modules.conf.orig
cp -av /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig
cp -av /etc/lighttpd/conf.d/cgi.conf /etc/lighttpd/conf.d/cgi.conf.orig
sed -i 's@.*\(include.*conf.d/cgi.conf"\).*@\1@' /etc/lighttpd/modules.conf
sed -i 's@.*server\.use-ipv6.*@server\.use-ipv6 = "disable"@' /etc/lighttpd/lighttpd.conf
sed -i 's@.*server\.bind.*@server\.bind = "localhost"@' /etc/lighttpd/lighttpd.conf
sed -i 's@.*server\.port.*@server\.port = 8888@' /etc/lighttpd/lighttpd.conf
semanage port -a -t http_port_t -p tcp 8888
systemctl restart lighttpd
systemctl status lighttpd
lsof -i -P -n | grep light
test -f /usr/bin/python && ln -s /usr/bin/python3 /usr/bin/python
mkdir -p /var/www/lighttpd/cgi-bin
vi /var/www/lighttpd/cgi-bin/test.cgi
------------------
#!/usr/bin/env python3
print("Content-Type: text/html") # HTMLが続きます
print() # 空行、ヘッダーの終わり
print("<html>")
print("<head><title>Hello CGI</title></head>")
print("<body>")
print("<h1>Hello World</h1>")
print("</body>")
print("</html>")
----------------------
chmod +x /var/www/lighttpd/cgi-bin/test.cgi
curl http://127.0.0.1:8888/cgi-bin/test.cgi
このロールでは、このオプションを提供するためのCGIを用意しました。tests/cgi-bin/option.pyに含まれているので、cgi-binディレクトリにコピーし、JSONファイルの場所を更新して呼び出してください。
これは現時点での概念実証であることに注意してください。
cp tests/cgi-bin/option.py /var/www/lighttpd/cgi-bin/option.cgi
chmod +x /var/www/lighttpd/cgi-bin/option.cgi
vi /var/www/lighttpd/cgi-bin/option.cgi # JSONファイルの場所を更新
その後、Rundeck内で次のように呼び出すことができます:
[ "Datacenter1" ]
[ "Cluster1" ]
[ "LUN_01_VM_Replica", "LUN_02_VM_Replicas" ]
これが非常に素晴らしいことです... あまり手間をかけずに。
ansible-galaxy install joe-speedboat.fact_inventory