てくなべ (tekunabe)

ansible / network automation / 学習メモ

[Ansible] ansible-lint 6.0.0 のインストールで ansible-core 2.12.3 も一緒にインストールされる

はじめに

先日 ansible-lint 6.0.0 がリリースされました。

github.com

.config/ansible-lint.yml を読み込むようになったり、ansible 2.9 や Python3.6、3.7 がサポートされなくなったり、フォーマット機能がつくなど変更がありました。

また、インストールしたときにも気がついたのですが、ansible-core をセットでインストールするようになりました。

Made ansible-core a direct dependency (#1888) @ssbarnea

インストールのドキュメントからは、

You need to either install the desired version of Ansible yourself or mention one of the helper extras:

とういう記載がなくなりました

ansible-lint 6.0.0 をインストールすることによって、ansible-core 2.12.3 もインストールされることを試したので結果をまとめます。

  • 動作確認環境

検証1: ほぼ素の venv から

素の venv に pip install pip --upgrade だけした状態から始めます。

事前

% pip list
Package    Version
---------- -------
pip        22.0.4
setuptools 60.5.0

ansible-lint 6.0.0 インストールとその後

ansible-lint をインストールします。現在は私の環境(Python 3.9.10) 6.0.0 がインストールされます。

% pip install ansible-lint
Collecting ansible-lint
  Using cached ansible_lint-6.0.0-py3-none-any.whl (136 kB)
Collecting wcmatch>=7.0
  Using cached wcmatch-8.3-py3-none-any.whl (42 kB)
Collecting pyyaml
  Using cached PyYAML-6.0-cp39-cp39-macosx_10_9_x86_64.whl (197 kB)
Collecting ansible-core>=2.12.0
  Using cached ansible-core-2.12.3.tar.gz (7.8 MB)
...(略)...

インストール後、確認すると ansiblec-core 2.12.3 もインストールされたことが確認できます。

% pip list                
Package          Version
---------------- -------
ansible-compat   2.0.0
ansible-core     2.12.3   # ここ
ansible-lint     6.0.0
bracex           2.2.1
...(略)...
yamllint         1.26.3

別のchangelogにも記載がありましたが、yamllint 入りますね。

検証2: ansible-core 2.11 系インストールの状態から

次は pip install pip --upgrade 後に

pip install ansible-core==2.11.9 

を実行した状態から始めます。

事前

ansible-core 2.11.9 がインストールされています。

 % pip list
Package      Version
------------ -------
ansible-core 2.11.9
cffi         1.15.0
cryptography 36.0.2
Jinja2       3.0.3
MarkupSafe   2.1.1
packaging    21.3
pip          22.0.4
pycparser    2.21
pyparsing    3.0.7
PyYAML       6.0
resolvelib   0.5.4
setuptools   60.5.0

ansible-lint 6.0.0 インストールとその後

ansible-lint をインストールします。途中、もともと入っていた ansibl-core 2.11.9 がアンインストールされるログも見受けられます。

% pip install ansible-lint
Collecting ansible-lint
  Using cached ansible_lint-6.0.0-py3-none-any.whl (136 kB)
Collecting ansible-core>=2.12.0
  Using cached ansible-core-2.12.3.tar.gz (7.8 MB)
  Preparing metadata (setup.py) ... done
...(略)...
Using legacy 'setup.py install' for yamllint, since package 'wheel' is not installed.
Installing collected packages: commonmark, subprocess-tee, ruamel.yaml.clib, pygments, pathspec, bracex, yamllint, wcmatch, ruamel.yaml, rich, ansible-compat, enrich, ansible-core, ansible-lint
  Running setup.py install for yamllint ... done
  Attempting uninstall: ansible-core
    Found existing installation: ansible-core 2.11.9
    Uninstalling ansible-core-2.11.9:
      Successfully uninstalled ansible-core-2.11.9
...(略)...

インストール後、確認すると ansible-core 2.12.3 もインストールされたことが確認できます。

% pip list                
Package          Version
---------------- -------
ansible-compat   2.0.0
ansible-core     2.12.3   # ここ
ansible-lint     6.0.0
bracex           2.2.1
...(略)...
yamllint         1.26.3

ansibleコマンド の バージョン表記も 2.12.3 になります。

 % ansible --version
ansible [core 2.12.3]

検証3: ansible 2.9 系インストールの状態からだとエラーに

一応・・。

今度は pip install pip --upgrade 後に

pip install ansible==2.9.27

を実行した状態から始めます。ansible 2.9 系からです。

事前

ansible 2.9.27 がインストールされている状態です。

 % pip list
Package      Version
------------ -------
ansible      2.9.27
cffi         1.15.0
cryptography 36.0.2
Jinja2       3.0.3
MarkupSafe   2.1.1
pip          22.0.4
pycparser    2.21
PyYAML       6.0
setuptools   60.5.0

ansible コマンドのバージョン表記も 2.9.27 です。

% ansible --version
ansible 2.9.27

ansible-lint 6.0.0 インストール(エラー)とその後

ansible-lint をインストールしようと試みます。エラーになりました。ansible 2.10 でパッケージの分け方が変更された関係で、ansible 2.9 以前から 2.10 以降にアップグレードする際は、いったん ansible をアンインストールしてくださいという件です。なので、ansible-lint そのものの事情というより、ansible の事情ということかなと思います。

ansible

% pip install ansible-lint
Collecting ansible-lint
  Using cached ansible_lint-6.0.0-py3-none-any.whl (136 kB)
Collecting yamllint>=1.25.0
  Using cached yamllint-1.26.3.tar.gz (126 kB)
  Preparing metadata (setup.py) ... done
...(略)...
Installing collected packages: resolvelib, commonmark, subprocess-tee, ruamel.yaml.clib, pyparsing, pygments, pathspec, bracex, yamllint, wcmatch, ruamel.yaml, rich, packaging, ansible-compat, enrich, ansible-core, ansible-lint
  Running setup.py install for yamllint ... done
  Running setup.py install for ansible-core ... error
  error: subprocess-exited-with-error
  
  × Running setup.py install for ansible-core did not run successfully.
  │ exit code: 1
  ╰─> [28 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/2s/h6djr0fn3773tj1zy4mg442c0000gn/T/pip-install-47xu8j2h/ansible-core_1efb8a412bd249b9a33bf132097bea90/setup.py", line 120, in <module>
          _validate_install_ansible_core()
        File "/private/var/folders/2s/h6djr0fn3773tj1zy4mg442c0000gn/T/pip-install-47xu8j2h/ansible-core_1efb8a412bd249b9a33bf132097bea90/setup.py", line 91, in _validate_install_ansible_core
          raise RuntimeError(
      RuntimeError:
      
          ****************************************************************************
      
          Cannot install ansible-core with a pre-existing ansible==2.9.27
          installation.
      
          Installing ansible-core with ansible-2.9 or older, or ansible-base-2.10
          currently installed with pip is known to cause problems. Please uninstall
          ansible and install the new version:
      
              pip uninstall ansible
              pip install ansible-core
      
          If you want to skip the conflict checks and manually resolve any issues
          afterwards, set the ANSIBLE_SKIP_CONFLICT_CHECK environment variable:
      
              ANSIBLE_SKIP_CONFLICT_CHECK=1 pip install ansible-core
      
          ****************************************************************************
      
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> ansible-core

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

事後はこうなりました。ansible-lint はインストールされていません。ansible 2.9.27 は残ったままです。

% pip list
Package          Version
---------------- -------
ansible          2.9.27
ansible-compat   2.0.0
bracex           2.2.1
cffi             1.15.0
commonmark       0.9.1
cryptography     36.0.2
enrich           1.2.7
Jinja2           3.0.3
MarkupSafe       2.1.1
packaging        21.3
pathspec         0.9.0
pip              22.0.4
pycparser        2.21
Pygments         2.11.2
pyparsing        3.0.7
PyYAML           6.0
resolvelib       0.5.4
rich             12.0.0
ruamel.yaml      0.17.21
ruamel.yaml.clib 0.2.6
setuptools       60.5.0
subprocess-tee   0.3.5
wcmatch          8.3
yamllint         1.26.3

Python 3.6、3.7系の場合 は ansible-lint 5系まで

ansible-lint 6.0.0 の changelogに、

Remove support for py36 and py37 (#1850) @ssbarnea

とあるように、Python 3.6 と 3.7 はサポートされなくなりました

そのため、たとえば、Python 3.6.8 の環境で pip install ansible-lint を実行しても、現在の場合 5.4.0 までしかインストールされません。なので、ansible-core はセットでインストールされません。

終わりに

ansible-lint 6.0.0 をインストールすることによって、ansible-core 2.12.3 もインストールされることを確認しました。

インストール時は少し注意が必要かなと思います。lint用の別のvenvを用意するのがよいでしょうか。

また、 ansible 2.9 の環境には ansible-lint 5 系までとセットで使うべし、ということも分かりました(ansible-lint 6.0.0 の changelog でいう Remove support for ansible 2.9)。

調べ中のメモ