てくなべ (tekunabe)

ansible / network automation / 学習メモ

[Ansible] ansible 2.10.0 で ini のインベントリファイルのansible_becomeのbool値解釈が修正された

はじめに

ini ファイル形式のインベントリファイルで指定された ansible_become 変数の値の解釈が ansible 2.10.0 で修正されました。

2.9 系との動作を比較して検証します。

前提となる ini 形式のインベントリファイル

[awx]
awx1

[awx:vars]
ansible_host=10.0.0.145
ansible_user=admin
ansible_become=hogehoge

become が true 扱いなら、リモートでも実行ユーザーが、root ユーザー、 false なら admin ユーザーとなります。

Ansible 2.9 系

whoami を実行する簡単なアドホックコマンドを実行します。

$ ansible --version
ansible 2.9.9
...(略)...
$ ansible -i inventory.ini awx1 -m command -a whoami
awx1 | CHANGED | rc=0 >>
admin

正常に完了し、admin と表示されました。つまり ansible_become=hogehogehogehogefalse 扱いです。

Ansible 2.10.1

先程同じアドホックコマンドを実行します。

$ ansible --version
ansible 2.10.1
...(略)...
$ ansible -i inventory.ini awx1 -m command -a whoami
awx1 | FAILED | rc=-1 >>
the field 'become' has an invalid value (hogehoge), and could not be converted to an bool.The error was: The value 'hogehoge' is not a valid boolean.  Valid booleans include: 0, 1, 'off', 'n', '1', 'y', 'true', '0', 'yes', 'no', 'f', 'on', 't', 'false'

hogehoge という値は正しい boolean 値でないというエラーになりました。有効な値は以下の通りとメッセージがあります。

0, 1, 'off', 'n', '1', 'y', 'true', '0', 'yes', 'no', 'f', 'on', 't', 'false'

試してみると、引き続き TrueFalse も(大文字はじまり)正常な boolean として扱われました。