is bool は template error while templating string
概要
プレイブックのwhen文でis trueを使っていたところ、ansible 2.10.5では動いていたが ansible-core 2.11.0rc2 で動かなくなった。 ※3/26時点の最新バージョンである2.12.3でも同様の結果
事象
ansible 2.10.5では動いていた以下のプレイブックがansibleをバージョンアップした所、動かなくなった。
- hosts: localhost name: Test connection: local gather_facts: False vars: b: True tasks: - name: Test debug: msg: "test" when: b is True
動かなかった時のエラー内容
fatal: [localhost]: FAILED! => {"msg": "The conditional check 'b is True' failed. The error was: template error while templating string: no test named 'True'. String: {% if b is True %} True {% else %} False {% endif %}\n\nThe error appears to be in ... : line 18, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: Test\n ^ here\n"}
おそらく、いつのバージョンからか is bool という書き方がサポートされなくなったと思われる。
解決策
== True(もしくは、比較の部分の記載を消して変数だけにする)
※冗長だけど、自分的には==Trueなどの記載があった方が分かりやすくて好き
そのため、以下のように変更したところ、問題なく動いた。
- hosts: localhost name: Test connection: local gather_facts: False vars: b: True tasks: - name: Test debug: msg: "test" when: b == True