■ 現象
junos_command や junos_config モジュールを netconf 接続で使用時に、Playbook などの書き方の不備により
fatal: [172.16.0.1]: FAILED! => {"msg": "'NoneType' object has no attribute 'startswith'"}
というエラーになってしまうことがあります。 (Ansible 2.6.1/ 2.6.2 で確認)
- playbook
- hosts: junos gather_facts: no tasks: - name: test junos_config: lines: - set system ntp server 10.0.0.123 vars: ansible_connection: netconf ansible_user: testuser ansible_ssh_pass: testpass
- インベントリファイル
[junos] 172.16.0.1
- 実行結果(エラー)
(ansible262) [vagrant@centos7 vagrant]$ ansible-playbook -i inventory junos_26.yml PLAY [junos] ******************************************************************************* TASK [command test] ************************************************************************ fatal: [172.16.0.1]: FAILED! => {"msg": "'NoneType' object has no attribute 'startswith'"} to retry, use: --limit @/vagrant/junos_26.retry PLAY RECAP ********************************************************************************* 172.16.0.1 : ok=0 changed=0 unreachable=0 failed=1
■ 対処 (ansible_network_os: junos
を指定)
公式ドキュメントに記載があるように、ansible_network_os
という変数に junos
をセットします。
- Playbook
- hosts: junos gather_facts: no tasks: - name: test junos_config: lines: - set system ntp server 10.0.0.123 vars: ansible_connection: netconf ansible_network_os: junos # 追加 ansible_user: testuser ansible_ssh_pass: testpass
一方、junos_command
モジュールと network_cli
コネクションタイプ(netconf
ではなく)の組み合わせで、この ansible_network_os
変数の指定を忘れると
fatal: [172.16.0.1]: FAILED! => {"msg": "Unable to automatically determine host network os. Please manually configure ansible_network_os value for this host"}
という親切なエラーメッセージが表示されるので、エラーハンドリングが甘めになっているのかも知れません。
なお、現在開発中の Ansible 2.7 で ansible_network_os
を指定せずに junos_config
モジュールを試した場合、親切なエラーメッセージが表示され・・るのではなく、正常に設定変更できてしまいました。(本エントリ執筆時点)