LoginSignup
4
5

More than 1 year has passed since last update.

Ansible | Playbook で変数を変数に代入する

Last updated at Posted at 2017-10-27

キー: "{{ 変数名 }}" で代入できる様子。(クォートが必要)

Playbook

playbook.yml
---
- hosts: example
  vars:
    variable1: MESSAGE
    variable2: "{{ variable1 }}"
  tasks:
    - debug: msg={{ variable2 }}

variable1variable2 に代入して debug 出力してみる。

インベントリ

inventory.txt
[example]
localhost

検証

$ ansible-playbook -i inventory.txt playbook.yml

PLAY [example] *******************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [debug msg={{ variable2 }}] *********************************************
ok: [localhost] => {
    "msg": "MESSAGE"
}

PLAY RECAP ********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0

環境

  • ansible 1.9.6

参考

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

4
5
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
4
5