Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send netconf session_close RPC only if connection is alive #684

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

efenian
Copy link

@efenian efenian commented Feb 1, 2025

Connection can be lost from control plane reset or device restart. meta: reset_connection task wll attempt to send a session_close RPC to a dead connection and ncclient will raise an exception preventing the connection socket_path from being closed out.

SUMMARY

Fixes #348

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

netconf connection

ADDITIONAL INFORMATION

meta: reset_connection attempts to close the connection:
https://github.com/ansible/ansible/blob/4cc47307ef2c5f63215f2eb1cffeabdeab1c59d6/lib/ansible/plugins/connection/__init__.py#L379

Which calls the netconf connection close:

self._manager.close_session()

If the conneciton was lost due to restart, ncclient raises exeption preventing the ansible socket from being closed:
https://github.com/ncclient/ncclient/blob/a641253370c632182a94b58aa53b66993b8c9a63/ncclient/transport/session.py#L257

This checks the connection status before attempting to send the RPC call to close the session.

- junos_facts:

- junos_command:
    commands: request system reboot

# ncclient connection will be lost

- wait_for::
     port: 830
     delay: 300
     timeout: 600
  delegate_to: localhost

# currently fails to close ansible socket
- meta: reset_connection

# existing socket found and ncclient raises exception
- junos_facts:

Connection can be lost from control plane reset or device restart.
meta: reset_connection task wll attempt to send a session_close RPC to a dead connection and ncclient will raise an exception preventing the connection socket_path from being closed out.
@NilashishC
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Netconf + Juniper routing engine switch
2 participants