LoginSignup
28
29

More than 5 years have passed since last update.

Ansible の YAML で「:」を使う方法

Last updated at Posted at 2013-09-09

Ansible で YAML ファイルの中で値の部分にコロンを入れると Syntax Error でコケます。
例えば /etc/sudoerslineinfile モジュールで書き換えようとして NOPASSWD: という文字列を入れちゃうとエラーになります。バックスラッシュではエスケープできませんでした。

ERROR: Syntax Error while loading YAML script, ...
Note: The error may actually appear before this position: line 1, column 63

これを回避する方法、それはコロンを変数に入れること...

group_vars/all
colon: ':'
NG
- lineinfile: >
    regexp='^%wheel'
    line='%wheel ALL=(ALL) NOPASSWD: ALL'
    dest=/etc/sudoers
OK
- lineinfile: >
    regexp='^%wheel'
    line='%wheel ALL=(ALL) NOPASSWD{{colon}} ALL'
    dest=/etc/sudoers

あ、でもこの例(sudoers)の場合は /etc/sudoers.d/ にファイルを置く方法にするのが良いと思います。

28
29
4

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
28
29