Junosデバイスの管理時に発生するAnsibleコレクションエラーとモジュールエラーのトラブルシューティング
以下のセクションでは、 juniper.device Ansibleコレクションを使用してJunos OSを実行しているデバイスとJunos OS Evolvedを実行しているデバイスを管理する場合に発生する可能性のあるエラーについて説明します。
問題点
説明
Ansibleプレイブックの実行中に、制御ノードは、 juniper.device モジュールまたは junipernetworks.junos モジュールを解決できなかった、またはタスクでアクションが検出されなかったというエラーを生成します。次に例を示します。
ERROR! couldn't resolve module/action 'juniper.device.facts'. This often indicates a misspelling, missing collection, or incorrect module path.
[ERROR]: couldn't resolve module/action 'junipernetworks.junos.junos_facts'. This often indicates a misspelling, missing collection, or incorrect module path.
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
原因
Ansible制御ノードは、juniper.deviceコレクションおよび関連モジュールを見つけることができません。リリース 2.0.0 以降juniper.deviceコレクションには、元の juniper.device モジュールに加えて、junipernetworks.junos モジュールが含まれています。
ソリューション
juniper.deviceコレクションは、Ansible GalaxyのWebサイトでホストされています。コレクション内のモジュールを使用するには、Ansible制御ノードにコレクションをインストールし、プレイブックで参照する必要があります。
Ansible制御ノードに juniper.device コレクションをインストールするには、 ansible-galaxy collection install コマンドを実行し、 juniper.deviceを指定します。
user@ansible-cn:~$ ansible-galaxy collection install juniper.device
コレクションをデフォルトの場所にインストールしない場合は、Ansibleセットアップでコレクションへのパスを定義する必要がある場合があります。コレクションのインストールとパスの指定についての詳細は、 公式の Ansible ドキュメントを参照してください。
juniper.device コレクション内のモジュールを使用するには、モジュールの実行時に完全修飾コレクション名を参照します。また、使用するモジュール セットに適した接続変数とネットワーク OS 変数を定義する必要があります。変数は、インベントリファイル、ホスト変数ファイル、グループ変数ファイル、プレイブック、コマンドライン引数など、さまざまな場所で定義できます。juniper.deviceモジュールセットの詳細については、Ansible for Junos OSコレクションおよびモジュールについてを参照してください。
次のプレイブックの例では、指定されたインベントリ ファイルを参照し、 juniper.device.facts モジュールを実行します。
# Inventory [junos] host1.example.com [junos:vars] ansible_connection=local
---
- name: Get Device Facts
hosts: junos
gather_facts: no
tasks:
- name: Get device facts
juniper.device.facts:
savedir: "{{ playbook_dir }}"
マージされたjuniper.deviceコレクションのjunipernetworks.junosモジュールを使用していて、プレイブックが引き続きjunipernetworks.junos名前空間を参照している場合は、次のようにします。
-
プレイブックで、
juniper.deviceを使用するように完全修飾コレクション名を更新します。 -
インベントリ ファイルで、
ansible_network_osをjuniper.device.junosに設定します。
次のプレイブックは、指定されたインベントリ ファイルを参照し、 juniper.device.junos_facts モジュールを実行します。
# Inventory [junos] host2.example.com [junos:vars] ansible_connection=ansible.netcommon.netconf ansible_network_os=juniper.device.junos
---
- name: Get Device Facts
hosts: junos
gather_facts: no
tasks:
- name: Get device facts
juniper.device.junos_facts:
junipernetworks.junos名前空間を参照するプレイブックを引き続き使用するには、juniper.deviceコレクションとjunipernetworks.junosコレクションの両方をインストールします。ただし、インベントリ ファイル内の Ansible ネットワーク OS 変数を更新する必要があります。