LoginSignup
0
0

More than 1 year has passed since last update.

[Ansible] 条件定義の基本

Last updated at Posted at 2018-07-10

assert モジュールを使って条件定義のテストをしてみる。

Playbookの例

例として known 変数が定義されており、 unknown 変数が定義されていない場合。
以下の検証は全てパスする

- hosts: localhost
  tasks:
    - assert:
        that:
          # 肯定条件
          - known is defined

          # 否定条件
          - unknown is not defined
          - not unknown is defined

          # 否定の否定
          - not known is not defined

          # and 条件
          - known is defined and unknown is not defined

          # or 条件
          - known is defined or known is not defined

          # 複雑な条件はカッコでくくることが出来る
          - not (known is defined and known is not defined)
      vars:
        known: true

環境

  • ansible 2.6.0

参考

チャットメンバー募集

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

Twitter

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