てくなべ (tekunabe)

ansible / network automation / 学習メモ

[Ansible/AAP] Automation Controller へのマニフェストファイル適用時にエラー「Request failed with status code 413」になる現象と対処

はじめに

Automation Controller にライセンスを適用する方法には以下の2つがあります。

  1. 予め作成したマニフェストファイル(zip)をライセンス適用画面でアップロード
  2. ライセンス適用画面でユーザー名 / パスワードを入力してライセンスを選択

このうち、1 のマニフェストファイルをアップロードした時に Request failed with status code 413 というになる現象に出会いました。

本記事では原因と対策を記載します。簡単にまとめると、アップロードするマニフェストファイルのサイズが大きくて nginx の制限に引っかかってしまったので制限を変更しました。

なお、本事象の調査の一通りし終えた後に、レッドハット社の以下の関連ナレッジを見つけました。閲覧できる方は、あわせてご参照ください。

環境

  • Automation Controller 4.1.2 (AAP 2.1 に含まれる)
    • すでに EOL を迎えていますが、アップグレードの準備や機能差分の調査などで利用する機会はなくもないと思います
    • Automation Controller 4.2 以降はいくつか事情が異なるのでご注意ください(詳細は「補足」にて)

現象

ライセンス未適用 の Automation Controller にログインすると以下の画面になります(適用済み Automation Controller の [設定] > [サブスクリプション設定] > [編集] でも類似の画面になります)。

サブスクリプション適用画面

ここで、予め Red Hat Customer Portal で有効なサブスクリプションから作成したマニフェストファイルの zip をアップロードして、「使用許諾契約書」まで進めて [送信] をクリックします。すると、Request failed with status code 413 というエラーが表示されました。

エラー Request failed with status code 413`

初見では、レッドハット社側のサイトからのエラーが表示されているように思いましたが、通信状況を確認すると、レッドハット社のサイトへの通信は発生していませんでした。そのため、Automation Controller 自身が 413、つまり Content Too Large を返していると判断しました。

原因

Automation Controller で利用されている nginx の client_max_body_size がデフォルトの 1m のままだったため、これを超えるサイズのマニフェストファイル(今回は1069KB)をアップロードできないのが原因でした。

これまで利用していたマニフェストファイルは 500KB 程度だったのでこの制限に引っかかりませでした。今回は作成する元のサブスクリプションが変わった影響かマニフェストファイルのサイズが大きくなって制限に引っかかってしまったようです。

対策

今回の環境ではなく次のバージョンの Automation Controller 4.3 からは client_max_body_size が デフォルトで 5m に設定されるようになっています。

そのため、今回の環境も 5m に設定することにしました。

/etc/nginx/nginx.confhttp > server 配下に client_max_body_size 5m; を追加します。

# ...(略)...
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    server_tokens off;

    # ...(略)...
    server {
        listen 443 default_server ssl;
        listen 127.0.0.1:80 default_server;

        client_max_body_size 5m;        # 追加

        # If you have a domain name, this is where to add it
        server_name _;
        keepalive_timeout 65;
        # ...(略)...

nginx 単体の再起動でもよいかもしれませんが、念のため automation-controller-service コマンドで再起動します。

$ sudo automation-controller-service restart

これで正常にマニフェストファイルをアップロード、ライセンス適用できました。

補足

今回は Automation Controller 4.1 での事象と対策でした。

他のバージョンの事情も少し調べたのでまとめておきます。ただし、AAP のインストーラーの処理を机上で追っただけです。

Automation Controller バージョン nginx 設定ファイル client_max_body_size 設定
4.1.2 (AAP 2.1) /etc/nginx/nginx.conf 指定なし(デフォルトの 1m
4.2.2 (AAP 2.2) /etc/nginx/nginx.conf 1m (変数 automationcontroller_client_max_body_size で変更可)
4.3.19 (AAP 2.3) /etc/nginx/conf.d/automation-controller.nginx.conf 5m (変数 automationcontroller_client_max_body_size で変更可)
4.5.5 (AAP 2.4) /etc/nginx/conf.d/automation-controller.nginx.conf 5m (変数 automationcontroller_client_max_body_size で変更可)

また、Automation Controller 4.3.7 のリリースノート

Made client_max_body_size for controller nginx configurable at install time for the VM installer,

とあります。変数化されているという意味であれば、私が調べた限りは、 4.2.2 でも変数化されていました。

おわりに

Automation Controller とエラー「Request failed with status code 413」を頼りに調べていた時は、なかなか解決の糸口が見つからなかったのですが、ファイルサイズに着目してナレッジを検索していれば、もう少し早く解決したかなと思いました。