Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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
YumaInaura
Ruby on Rails 業務経験 約5年 / Perl PHP Python Golang Linux Apache MySQL BigQuery Jenkins ansible AWS など / いなうらゆうま / YumaInaura / 稲浦悠馬
http://twitter.com/yumainaura
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away