LoginSignup
0
0

More than 1 year has passed since last update.

Ansible lintとは?

Last updated at Posted at 2022-11-30

こちらの記事はAnsible lint Advent Calendar 2022 1日目の記事になります。

今回はAnsible lintとは何かについて解説します。

Ansible lintとは

Ansible playbook、role、collectionsを開発するためのコマンドライン型のlintツールです。lintツールとはコードが

  • ベストプラクティスに準じて記述されているか
  • バグにつながりやすい記述方法が紛れ込んでないか
  • コード等に脆弱性が入り込んでいないか

などを検査する静的解析ツールです。Ansible lintの製品のコンセプトとしては blackprettier の影響を強く受けていると言う事です。

Ansible lintの哲学

以下Ansible lintのウェブサイトからの意訳です。

  • Ansible playbooks、roles、およびcollections(以下Ansibleコンテンツと同義)は、ドキュメントのように読むことができ、曖昧さがなく、記述した通りに実行され、一貫した結果(冪等性と同義と思われる)を提供する

  • Ansible-lintは、Ansibleコンテンツの作成者がコンテンツを作成し、パッケージ化するための信頼すべき指針となるべきである

  • AnsibleコンテンツではAnsible lintが提示する全てのルールが適応されるべきであるとは限らないが、可能な限りAnsible lintの提示するルールに従うべきである

  • Ansible lintの目標は、異なる人々によって作成されたコンテンツが、似たような馴染みのある記述方法で作成される事を保証する。これにより、コミュニティや企業において、Ansibleコンテンツの採用や利用を容易にする

動作環境

Ansible lintのドキュメント等に明確には書いてありません。しかしAnsible lintのGitHubリポジトリのCI環境から推測するにPython 3.8以降が必要になります。

記事執筆時で最新バージョンのAnsible lint 6系より古いバージョンを利用する場合はGitHubリポジトリのテストの実行ファイルを確認してみてください。

.github/workflows/tox.yml
.
.
.
 unit:
    name: ${{ matrix.name || matrix.tox_env }}
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: ${{ matrix.shell || 'bash'}}
    strategy:
      fail-fast: false
      # max-parallel: 5
      # The matrix testing goal is to cover the *most likely* environments
      # which are expected to be used by users in production. Avoid adding a
      # combination unless there are good reasons to test it, like having
      # proof that we failed to catch a bug by not running it. Using
      # distribution should be preferred instead of custom builds.
      matrix:
        name:
          - py38
        tox_env:
          - py38
        python-version:
          - 3.8
        os:
          # https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
          - ubuntu-20.04
        # - windows-latest
        # - windows-2016
        include:
          # keep list sorted as it determines UI order too
          # linux
          # py38 is first and comes from matrix
          - tox_env: py38
            os: ubuntu-20.04
            python-version: 3.8
            devel: false # ansible 2.14 removed support for py38
          - tox_env: py39
            os: ubuntu-20.04
            python-version: 3.9
            devel: true
          - tox_env: py310
            os: ubuntu-20.04
            python-version: "3.10"
            devel: true
          - tox_env: py311
            os: ubuntu-20.04
            python-version: "~3.11.0-0" # see https://github.com/actions/setup-python/issues/213#issuecomment-1146676713
            devel: true
          # macos
          - name: py38 (macos)
            tox_env: py38
            os: macOS-latest
            python-version: 3.8
          - name: py310 (macos)
            tox_env: py310
            os: macOS-latest
            python-version: "3.10"
          # windows-2022 WSL does timeout running tests, likely caused but some
          # extreme (>10x) performance degradation compared with windows-2019
          # https://github.com/actions/virtual-environments/issues/4856
          - name: py39 (wsl)
            tox_env: py39
            os: windows-2019
            shell: "wsl-bash {0}"
.
.
.

インストール方法

pipによりインストールします。以下のコマンドによりAnsible lintおよびAnsible coreがインストールされます。

pip3 install ansible-lint

## もしくは

pip3 install git+https://github.com/ansible-community/ansible-lint.git

しかしAnsible lintの機能を全て利用する場合はAnsible Community Packageも必要になるためAnsible Community Packageもあわせてインストールします。

pip3 install ansible-lint ansible
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