てくなべ (tekunabe)

ansible / network automation / 学習メモ / 思考メモ

[Ansible/AAP] 各プロダクトへの API による ping や status をまとめて確認できる /api/gateway/v1/status/

はじめに

Automation Controller には /api/v2/ping/ という API エンドポイントがあり、簡単な情報が得られます。この記事では API ping と呼ぶことにします。

Automation Controller の /api/v2/ping/ リファレンスから

以下のページ(Ansible Tower 時代)でも /api/v2/ping/ が紹介されています。

rheb.hatenablog.com

これに加え、以前の記事でもちらっと紹介しましたが、/api/gateway/v1/status/ というエンドポイントもあります。Platform GatewayAPI 経由で、配下の Automation Controller の API Ping や Automation Hub などの status が確認できます。ただし認証が必要です。Platform Gateway 経由なので AAP 2.5 で対応しています。

改めて見ると便利だなと思ったので、レスポンスのサンプルをいくつか掲載します。

  • 検証環境
    • AAP 2.5 2024/12/28 パッチリリース(コンテナベース)
      • Automation Controller 4.6.3
      • Automation Hub 4.10.1
      • EDA Controller 1.1.3
      • ホスト 192.168.1.5 にすべてのコンテナを配置

/api/gateway/v1/status/ のサンプル

すべて正常の場合

{
    "time": "2025-03-19T12:40:28.764471",
    "status": "good",
    "services": {
        "controller": {
            "status": "good",
            "nodes": {
                "192.168.1.5:8443": {
                    "url": "https://192.168.1.5:8443/api/v2/ping/",
                    "status": "good",
                    "response": {
                        "ha": false,
                        "version": "4.6.3",
                        "active_node": "192.168.1.5",
                        "install_uuid": "2e33d634-acac-43a0-9114-621f86ad9b21",
                        "instances": [
                            {
                                "node": "192.168.1.5",
                                "node_type": "hybrid",
                                "uuid": "65884d56-0636-8b8d-4343-eb43413873ac",
                                "heartbeat": "2025-03-19T12:39:53.949236Z",
                                "capacity": 136,
                                "version": "4.6.3"
                            }
                        ],
                        "instance_groups": [
                            {
                                "name": "controlplane",
                                "capacity": 136,
                                "instances": [
                                    "192.168.1.5"
                                ]
                            },
                            {
                                "name": "default",
                                "capacity": 136,
                                "instances": [
                                    "192.168.1.5"
                                ]
                            }
                        ]
                    }
                }
            }
        },
        "hub": {
            "status": "good",
            "nodes": {
                "192.168.1.5:8444": {
                    "url": "https://192.168.1.5:8444/pulp/api/v3/status/",
                    "status": "good",
                    // ...(略)...
                }
            }
        },
        "eda": {
            "status": "good",
            "nodes": {
                "192.168.1.5:8445": {
                    "url": "https://192.168.1.5:8445/api/eda/v1/status/",
                    "status": "good",
                    "response": {
                        "status": "OK"
                    }
                }
            }
        },
        "redis": {
            "mode": "standalone",
            "status": "good",
            "ping": true
        }
    }
}

Automation Controller が停止している場合

コンテナ automation-controller-websystemctl stop automation-controller-web.service --user で停止させた状態での場合のレスポンスです。

この場合でも レスポンスコードは 200 である点は注意です。

controllerstatusfailedで、hubedastatusgood です。

{
    "time": "2025-03-19T12:18:04.346283",
    "status": "failed",
    "services": {
        "controller": {
            "status": "failed",
            "nodes": {
                "192.168.1.5:8443": {
                    "url": "https://192.168.1.5:8443/api/v2/ping/",
                    "status": "failed",
                    "exception": "HTTPSConnectionPool(host='192.168.1.5', port=8443): Max retries exceeded with url: /api/v2/ping/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f155848aed0>: Failed to establish a new connection: [Errno 111] Connection refused'))"
                }
            }
        },
        "hub": {
            "status": "good",
            "nodes": {
                "192.168.1.5:8444": {
                    "url": "https://192.168.1.5:8444/pulp/api/v3/status/",
                    "status": "good",
                    "response": {
                    // ...(略)...
                    }
                }
            }
        },
        "eda": {
            "status": "good",
            "nodes": {
                "192.168.1.5:8445": {
                    "url": "https://192.168.1.5:8445/api/eda/v1/status/",
                    "status": "good",
                    "response": {
                        "status": "OK"
                    }
                }
            }
        },
        "redis": {
            "mode": "standalone",
            "status": "good",
            "ping": true
        }
    }
}

なお、この際 /api/controller/ 配下の API エンドポイントはエラーになります。

(比較用) 個別の API ping サンプル

比較、参考のため、同じ環境を利用して各プロダクト個別の API ping の例も2つ掲載します。

Platform Gateway への API ping

GET /api/gateway/v1/ping/

{
    "version": "2.5",
    "pong": "2025-03-19 09:12:33.928346",
    "status": "good",
    "db_connected": true,
    "proxy_connected": true
}

Automation Controller への API ping

GET /api/controller/v2/ping/

{
    "ha": false,
    "version": "4.6.3",
    "active_node": "192.168.1.5",
    "install_uuid": "2e33d634-acac-43a0-9114-621f86ad9b21",
    "instances": [
        {
            "node": "192.168.1.5",
            "node_type": "hybrid",
            "uuid": "65884d56-0636-8b8d-4343-eb43413873ac",
            "heartbeat": "2025-03-19T09:13:14.048393Z",
            "capacity": 136,
            "version": "4.6.3"
        }
    ],
    "instance_groups": [
        {
            "name": "controlplane",
            "capacity": 136,
            "instances": [
                "192.168.1.5"
            ]
        },
        {
            "name": "default",
            "capacity": 136,
            "instances": [
                "192.168.1.5"
            ]
        }
    ]
}

おわりに

AAP 2.5 の各プロダクトへの API ping や status を、Platform Gateway 経由でまとめて確認できるエンドポイント /api/gateway/v1/status/ のご紹介をしました。

認証が必要ではありますが、まとめて確認できるのは便利だなと思いました。