LoginSignup
0
0

More than 1 year has passed since last update.

【ルール説明・basic】key-order

Last updated at Posted at 2022-12-24

こちらの記事は Ansible lint Advent Calendar 2022 カレンダー2 7日目の記事になります。

今回はルール key-order について説明します。

key-order

key-order はコードの保守を容易にし、エラーを少なくするために、Ansible コンテンツのキーの順序を変更することを推奨しています。key-order に違反すると警告が出力されます。

以下は推奨される書き方です。

  • play、task、handler では、name が常に最初のキーでなければならない
  • タスクの場合、block、rescue、always のキーは最後のキーでなければならない

問題のあるコード

---
- hosts: localhost
  name: This is a playbook # <-- name キーが最初に記述されていない
  tasks:
    - name: A block
      block:
        - name: Display a message
          debug:
            msg: "Hello world!"
      when: true # <-- when キーは block キーの前に記述する

修正されたコード

---
- name: This is a playbook
  hosts: localhost
  tasks:
    - name: A block
      when: true
      block:
        - name: Display a message
          debug:
            msg: "Hello world!"

参考サイト

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