5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ansibleのtemplateでエスケープ

Posted at

下記要件の時にちょっと調べたのでメモ

  • 複数のサーバに対する処理をするシェルスクリプトを配布
  • 対象のサーバは増えてもいいようにansibleのinventoryを使って管理したい
NODES=("10.0.1.1" "10.0.1.2" "10.0.1.3")
i=`expr $RANDOM % ${#NODES[@]}`

こんなコードを書いてましたが実行したらエラーが.....

error: Missing end of comment tag'

ansibleで使っているテンプレートエンジンはjinja2というものです

エラー内容からも分かる通り {# がjinja2側でコメントアウトとして認識されてしまったみたいです

なのでドキュメント見に行きました

しっかり載ってますね!

下記方法で解決

{{ 'i=`expr $RANDOM % ${#NODES[@]}`' }}
5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?