はじめに
ansible-core 2.14.0 の changelog を眺めてて始めて気がついたのですが、INVENTORY_UNPARSED_WARNING という設定項目が追加されていました。
インベントリファイルを読み込めなかったときに表示される警告、[WARNING]: No inventory was parsed, only implicit localhost is available (略) を表示するかどうかという設定項目です。デフォルトは今までとおりの挙動である True です。
実際どんな感じだろうと思って確かめてみました。
- 動作確認環境
- ansible core 2.14.3
True の場合 (デフォルト)
そのそもどんな感じだっけ?ということで、デフォルトのまず試します。
Playbookはこちら。hosts: localhost としています。
--- - name: Test Play hosts: localhost gather_facts: false tasks: - name: Debug ansible.builtin.debug: msg: "{{ inventory_hostname }}"
ansible-playbook コマンドでインベントリファイルを指定せずに実行します。
% ansible-playbook test.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 [Test Play] ****************************************************************************************************
TASK [Debug] ********************************************************************************************************
ok: [localhost] => {
"msg": "localhost"
}
PLAY RECAP **********************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
例の警告が表示されました。
False の場合
INVENTORY_UNPARSED_WARNING は、環境変数 ANSIBLE_INVENTORY_UNPARSED_WARNING や ansible.cfg で設定できるようです。
今回は、ansible.cfg で設定してみます。defaults セクションではなく inventory セクションです。
[inventory] inventory_unparsed_warning=False
おなじく、インベントリファイルを指定せずに実行します。
% ansible-playbook test.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not
match 'all'
PLAY [Test Play] ****************************************************************************************************
TASK [Debug] ********************************************************************************************************
ok: [localhost] => {
"msg": "localhost"
}
PLAY RECAP **********************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[WARNING]: No inventory was parsed, 略 が表示されなくなりました。
おわりに
あまり設定変更したいときは多くないかもしれませんが、少しでも警告表示を抑えたい場合にはいいかもしれません。