Skip to content
Snippets Groups Projects
Commit 1760aed6 authored by Mohammad Torkashvand's avatar Mohammad Torkashvand
Browse files

test

parent 10bf0f15
Branches
Tags
No related merge requests found
Pipeline #94933 failed
[defaults]
host_key_checking = False
collections_paths = ~/.ansible/collections:/usr/share/ansible/collections
plugin_paths = ./modules:./connection:./module_utils:./netconf:./plugin_utils
[netconf_connection]
ssh_config = False
...@@ -403,6 +403,18 @@ class Connection(NetworkConnectionBase): ...@@ -403,6 +403,18 @@ class Connection(NetworkConnectionBase):
self._manager = manager.connect(**params) self._manager = manager.connect(**params)
self._manager._timeout = self.get_option("persistent_command_timeout") self._manager._timeout = self.get_option("persistent_command_timeout")
if self._config_mode == "private" and "junos" in self._network_os.lower():
open_rpc = (
'<open-configuration '
'xmlns="http://xml.juniper.net/xnm/1.1/xnm" '
'private="true"/>'
)
try:
# exec_command() will wrap to_ele(...) + manager.rpc(...)
self.exec_command(open_rpc)
self.queue_message("log", "opened Junos private candidate")
except Exception as e:
raise AnsibleError(f"Failed to open private candidate: {to_text(e)}")
except SSHUnknownHostError as exc: except SSHUnknownHostError as exc:
raise AnsibleConnectionFailure(to_native(exc)) raise AnsibleConnectionFailure(to_native(exc))
except AuthenticationError as exc: except AuthenticationError as exc:
...@@ -438,6 +450,16 @@ class Connection(NetworkConnectionBase): ...@@ -438,6 +450,16 @@ class Connection(NetworkConnectionBase):
self._manager.close_session() self._manager.close_session()
super(Connection, self).close() super(Connection, self).close()
# if self._config_mode == "private" and "junos" in self._network_os.lower():
# close_rpc = (
# '<close-configuration '
# 'xmlns="http://xml.juniper.net/xnm/1.1/xnm"/>'
# )
# try:
# self.exec_command(close_rpc)
# except Exception:
# pass
def set_config_mode(self, config_mode): def set_config_mode(self, config_mode):
"""Set the config_mode passed from the module.""" """Set the config_mode passed from the module."""
if config_mode: if config_mode:
......
[junos]
my-junos ansible_host=62.40.119.4 ansible_user=gap-test ansible_password=concept_gear_ESSENTIAL93 ansible_connection=geant.gap_ansible.netconf ansible_network_os=geant.gap_ansible.junos
...@@ -437,18 +437,18 @@ def main(): ...@@ -437,18 +437,18 @@ def main():
supports_check_mode=True, supports_check_mode=True,
) )
# if the user asked for private config mode, tell the connection # # if the user asked for private config mode, tell the connection
cfg_mode = module.params.get("config_mode") # cfg_mode = module.params.get("config_mode")
if cfg_mode: # if cfg_mode:
open_rpc = ( # open_rpc = (
'<open-configuration ' # '<open-configuration '
'xmlns="http://xml.juniper.net/xnm/1.1/xnm" ' # 'xmlns="http://xml.juniper.net/xnm/1.1/xnm" '
'private="true"/>' # 'private="true"/>'
) # )
try: # try:
module._connection.exec_command(open_rpc) # module._connection.exec_command(open_rpc)
except Exception as e: # except Exception as e:
module.fail_json(msg=f"Failed to open private candidate: {to_text(e)}") # module.fail_json(msg=f"Failed to open private candidate: {to_text(e)}")
warnings = list() warnings = list()
check_args(module, warnings) check_args(module, warnings)
...@@ -540,15 +540,15 @@ def main(): ...@@ -540,15 +540,15 @@ def main():
result["changed"] = True result["changed"] = True
if cfg_mode == 'private': # if cfg_mode == 'private':
close_rpc = ( # close_rpc = (
'<close-configuration ' # '<close-configuration '
'xmlns="http://xml.juniper.net/xnm/1.1/xnm"/>' # 'xmlns="http://xml.juniper.net/xnm/1.1/xnm"/>'
) # )
try: # try:
module._connection.exec_command(close_rpc) # module._connection.exec_command(close_rpc)
except Exception: # except Exception:
pass # session teardown will close it anyway # pass # session teardown will close it anyway
module.exit_json(**result) module.exit_json(**result)
......
- name: Test private-candidate junos_config
hosts: junos
gather_facts: no
collections:
- geant.gap_ansible # <-- your locally installed collection
tasks:
- name: Open private candidate, push a change and commit
geant.gap_ansible.junos_config: # <-- module from geant.gap_ansible
lines:
- set system services ssh root-login allow
config_mode: private
register: result
- debug:
var: result
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment