LoginSignup
0
0

More than 1 year has passed since last update.

【ルール説明・basic】deprecated-command-syntax

Posted at

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

今回はルールdeprecated-command-syntaxについて説明します。

deprecated-command-syntax

deprecated-command-syntax は省略記法が使われていないか検証します。省略記法を採用した書き方はデバッグが困難になりやすく推奨されません。

一部の Ansible モジュールではfree-formと言ってモジュールのキーに対して直接パラメーターを渡せるものがあります。この時に省略記法が使われているかどうかを検証するのが deprecated-command-syntax とも言えます。

free-form の例

free-form で書かれた処理

- name: Run command if /path/to/database does not exist (without 'args')
  ansible.builtin.command: /usr/bin/make_database.sh db_user db_name creates=/path/to/database

推奨される書き方

- name: Run command if /path/to/database does not exist (with 'args' keyword)
  ansible.builtin.command: /usr/bin/make_database.sh db_user db_name
  args:
    creates: /path/to/database

# もしくは

- name: Run command if /path/to/database does not exist (with 'cmd' parameter)
  ansible.builtin.command:
    cmd: /usr/bin/make_database.sh db_user db_name
    creates: /path/to/database

問題のあるコード

---
- name: Example playbook
  hosts: localhost
  tasks:
    - name: Perform chmod
      ansible.builtin.command: creates=B chmod 644 A # <-- 省略記法が使われている

修正されたコード

---
- name: Example playbook
  hosts: localhost
  tasks:
    - name: Perform chmod
      ansible.builtin.command: chmod 644 A
      args:
        creates: B

参考サイト

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