0
0

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]変数渡し( -e オプションで変数設定を羅列しないスマートな方法 )

Posted at

概要

Ansibleで作成したツールに複数の値を渡す場合、思わず-eに頼ってしまいがちだが、playbookの書き方を一工夫することでスマートに値を渡すことができるようになる。

コード

playbook.yml
- hosts: all
  gather_facts: no
  vars_files:
  - '{{ fl_param }}'

  tasks:
  - debug:
      var: parameter
/tmp/parameter.yml
parameter:
  hoge: hogehoge
  fuga: 
  - foo
  - bar
  - baz
  piyo:
    p1: swallow
    p2: sparrow

実行コマンド

$ ansible-playbook -i localhost, -e "fl_param=/tmp/parameter.yml" playbook.yml

アウトプット(抜粋)

TASK [debug] *************************************************
ok: [localhost] => {
    "parameter": {
        "fuga": [
            "foo",
            "bar",
            "baz"
        ],
        "hoge": "hogehoge",
        "piyo": {
            "p1": "swallow",
            "p2": "sparrow"
        }
    }
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?