LoginSignup
7
4

More than 1 year has passed since last update.

Ansible | when で true / false を判定する

Last updated at Posted at 2018-07-04

boolean の値をそのまま when に渡すだけで良い。
否定でマッチさせる場合は not を付ける。

ちなみに is true / is false などとは書かない。

playbook の例

- hosts: localhost
  tasks:
    - set_fact:
        true_variable: true
        false_variable: false

    - debug:
        msg: "when true"
      when: true_variable
    
    - debug:
        msg: "when not false"
      when: not false_variable

実行例

$ ansible-playbook -i ~/development playbooks/when.yml

TASK [set_fact] *********************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [debug] ************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": "when true"
}

TASK [debug] ************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": "when not false"
}


環境

  • ansible 2.6.0

チャットメンバー募集

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

Twitter

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