てくなべ (tekunabe)

ansible / network automation / 学習メモ

[Ansible] nclu モジュールでエラー「Error in pending config. You may want to view `net pending` on this target.」発生時はbecomeを確認

はじめに

Ansible には Cumulus Linux のネットワーク管理コマンドツール nclu を扱う nclu モジュールがあります。

先日、試しに使ってみたところ以下のエラーになりました。

Error in pending config. You may want to view `net pending` on this target.

ピンとこなかったのですが、結果的には become: true のつけ忘れでした。

この記事では、発生したときのPlaybook、実行例、その対策を紹介します。

  • 動作確認環境
    • Ansible 2.9.7

発生の経緯

以下のような Playbook を利用しました。Plyabook 中には登場しませんが、利用するユーザーは vagrant という一般ユーザーです。

この記事ベースで環境を作成

---
- hosts: leaf01
  gather_facts: false

  tasks:
    - name: show bgp summary json
      nclu:
        commands:
          - show bgp summary json
      register: result_bgp_summary_raw

実行結果はこちら。

$ ansible-playbook -i intentory.ini assert_bgp.yml 

PLAY [leaf01] *************************************************************************************************************************

TASK [show bgp summary json] **********************************************************************************************************
fatal: [leaf01]: FAILED! => {"changed": false, "msg": "Error in pending config. You may want to view `net pending` on this target."}

PLAY RECAP ****************************************************************************************************************************
leaf01                     : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

対策(become: true 追加)

一般ユーザーで net show コマンドを実行すると

vagrant@leaf01:mgmt:~$ net show interface
ERROR: You do not have permission to execute that command.

のようなエラーになることを思い出したので、権限周りが原因だと思いました。

そこで以下のように become: true を追加したらうまくいきました、

---
- hosts: leaf01
  gather_facts: false
  become: true    # 追加

  tasks:
    - name: show bgp summary json
      nclu:
        commands:
          - show bgp summary json
      register: result_bgp_summary_raw

参考

[2020/05/03 追記]

Cumulus 側で、ユーザーをグループに追加する方法もあるようです。