てくなべ (tekunabe)

ansible / network automation / 学習メモ

[ansible] あのモジュール、どのコレクションにいった?を探す

はじめに

Ansible(-base) 2.10 から、多くのモジュールはコレクションという管理、配布方式に移行しました

その関係で「前あったあのモジュール、プラグインはどのコレクションにいったんだ?」と気になることがあるかもしれません。

正確には、しれませんではなく、ありました。

調べた方をまとめておきます。

方法1: リダイレクトの定義ファイルを見る

ansible 本体に、モジュール名のみ(コレクション指定なし)が指定されたときに、どのコレクションのものとして扱うかという、リダイレクトの定義ファイルがあります。

これを見ると、どのコレクションになったのかが分かります。

github.com

インストールした環境にも ansible_builtin_runtime.yml があるはずです。

たとえば、ios_config モジュールであれば、modules 配下の ios_config を探します。

    ios_config:
      redirect: cisco.ios.ios_config

これにより、cisco.ios コレクションのものであることが分かります。

他にもyaml コールバックプラグインであれば、 callback 配下の yaml を探します。

    yaml:
      redirect: community.general.yaml

これにより、community.general コレクションのものであることが分かります。

方法2: ansible-doc で確認する

手元の環境で、移行先のコレクションがインストールされいることが前提ですが、ansible-doc コマンドでも確認できます。

ios_config モジュールの例

$ ansible-doc ios_config
> CISCO.IOS.IOS_CONFIG    (/home/admin/.ansible/collections/ansible_collections/cisco/ios/plugins/modules/ios_config.py)

        Cisco IOS configurations use a simple block indent file syntax for segmenting configuration

callback コールバックプラグインの例

$ ansible-doc -t callback yaml
> COMMUNITY.GENERAL.YAML    (/home/admin/.ansible/collections/ansible_collections/community/general/plugins/callback/yaml.py)

        Ansible output that can be quite a bit easier to read than the default JSON formatting.

-t には以下の値を指定できます (ansible-core 2.12.0の場合)。

  • become
  • cache
  • callback
  • cliconf
  • connection
  • httpapi
  • inventory
  • lookup
  • netconf
  • shell
  • vars,module
  • strategy
  • role
  • keyword

方法3: Playbook 実行時のリダイレクトログで確認する

こちらも手元の環境で、移行先のコレクションがインストールされいることが前提です。

ansible-playbook コマンド実行時に -vv をつけると、以下のようにリダイレクトの様子が見て取れます。

影響を出さないために --check を併用してもいいかもしれません。

redirecting (type: callback) ansible.builtin.yaml to community.general.yaml

記憶が定かではないのですが、一部は -vvv くらいまで付けないと見れなかった気もします。

実行例

$ ansible-playbook -i inventory.ini ios_show.yml -vv
ansible-playbook [core 2.12.4]
  config file = /home/admin/ansible.cfg
  configured module search path = ['/home/admin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/admin/venv/ansible/lib64/python3.8/site-packages/ansible
  ansible collection location = /home/admin/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/admin/venv/ansible/bin/ansible-playbook
  python version = 3.8.6 (default, Jan 22 2021, 11:41:28) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
  jinja version = 3.0.3
  libyaml = True
Using /home/admin/ansible.cfg as config file
redirecting (type: action) cisco.ios.command to cisco.ios.ios
redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: ios_show.yml *******************************************************************************************************************************************
1 plays in ios_show.yml

PLAY [ios1] ******************************************************************************************************************************************************
META: ran handlers
redirecting (type: action) cisco.ios.command to cisco.ios.ios

TASK [aa] ********************************************************************************************************************************************************
task path: /home/admin/ios_show.yml:12
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
redirecting (type: action) cisco.ios.command to cisco.ios.ios
redirecting (type: action) cisco.ios.command to cisco.ios.ios
redirecting (type: modules) cisco.ios.command to cisco.ios.ios_command
ok: [ios1] => changed=false 
# ...(略)...