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

test

parent 10bf0f15
No related branches found
No related tags found
No related merge requests found
Pipeline #94932 failed
[defaults]
library = ./modules
host_key_checking = False
[netconf_connection]
ssh_config = False
......@@ -403,6 +403,18 @@ class Connection(NetworkConnectionBase):
self._manager = manager.connect(**params)
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:
raise AnsibleConnectionFailure(to_native(exc))
except AuthenticationError as exc:
......@@ -438,6 +450,16 @@ class Connection(NetworkConnectionBase):
self._manager.close_session()
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):
"""Set the config_mode passed from the module."""
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():
supports_check_mode=True,
)
# if the user asked for private config mode, tell the connection
cfg_mode = module.params.get("config_mode")
if cfg_mode:
open_rpc = (
'<open-configuration '
'xmlns="http://xml.juniper.net/xnm/1.1/xnm" '
'private="true"/>'
)
try:
module._connection.exec_command(open_rpc)
except Exception as e:
module.fail_json(msg=f"Failed to open private candidate: {to_text(e)}")
# # if the user asked for private config mode, tell the connection
# cfg_mode = module.params.get("config_mode")
# if cfg_mode:
# open_rpc = (
# '<open-configuration '
# 'xmlns="http://xml.juniper.net/xnm/1.1/xnm" '
# 'private="true"/>'
# )
# try:
# module._connection.exec_command(open_rpc)
# except Exception as e:
# module.fail_json(msg=f"Failed to open private candidate: {to_text(e)}")
warnings = list()
check_args(module, warnings)
......@@ -540,15 +540,15 @@ def main():
result["changed"] = True
if cfg_mode == 'private':
close_rpc = (
'<close-configuration '
'xmlns="http://xml.juniper.net/xnm/1.1/xnm"/>'
)
try:
module._connection.exec_command(close_rpc)
except Exception:
pass # session teardown will close it anyway
# if cfg_mode == 'private':
# close_rpc = (
# '<close-configuration '
# 'xmlns="http://xml.juniper.net/xnm/1.1/xnm"/>'
# )
# try:
# module._connection.exec_command(close_rpc)
# except Exception:
# pass # session teardown will close it anyway
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