@ -16,7 +16,7 @@ version_added: "2.6"
options :
host :
description :
- Specifies the remote device FQDN or IP address to establish the SS H
- Specifies the remote device FQDN or IP address to establish the HTTP( S )
connection to .
default : inventory_hostname
vars :
@ -25,7 +25,8 @@ options:
type : int
description :
- Specifies the port on the remote device to listening for connections
when establishing the SSH connection .
when establishing the HTTP ( S ) connection .
When unspecified , will pick 80 or 443 based on the value of use_ssl
ini :
- section : defaults
key : remote_port
@ -33,6 +34,7 @@ options:
- name : ANSIBLE_REMOTE_PORT
vars :
- name : ansible_port
- name : ansible_httpapi_port
network_os :
description :
- Configures the device platform network operating system . This value is
@ -139,6 +141,7 @@ from ansible.errors import AnsibleConnectionFailure
from ansible . module_utils . _text import to_bytes
from ansible . module_utils . six import PY3
from ansible . module_utils . six . moves import cPickle
from ansible . module_utils . six . moves . urllib . error import URLError
from ansible . module_utils . urls import open_url
from ansible . playbook . play_context import PlayContext
from ansible . plugins . loader import cliconf_loader , connection_loader , httpapi_loader
@ -243,13 +246,13 @@ class Connection(ConnectionBase):
network_os = self . _play_context . network_os
protocol = ' https ' if self . get_option ( ' use_ssl ' ) else ' http '
host = self . _play_context. remote_addr
port = self . _play_context. port or 443 if protocol == ' https ' else 80
host = self . get_option( ' host ' )
port = self . get_option( ' port ' ) or ( 443 if protocol == ' https ' else 80 )
self . _url = ' %s :// %s : %s ' % ( protocol , host , port )
self . _cliconf = cliconf_loader . get ( network_os , self )
if self . _cliconf :
display . vvvv ( ' loaded cliconf plugin for network_os %s ' % network_os , host = self . _play_context . remote_addr )
display . vvvv ( ' loaded cliconf plugin for network_os %s ' % network_os , host = host )
else :
display . vvvv ( ' unable to load cliconf for network_os %s ' % network_os )
@ -295,9 +298,17 @@ class Connection(ConnectionBase):
'''
Sends the command to the device over api
'''
url_kwargs = dict ( url_username = self . _play_context . remote_user , url_password = self . _play_context . password )
url_kwargs = dict (
url_username = self . get_option ( ' remote_user ' ) , url_password = self . get_option ( ' password ' ) ,
timeout = self . get_option ( ' timeout ' ) ,
)
url_kwargs . update ( kwargs )
response = open_url ( self . _url + path , data = data , * * url_kwargs )
try :
response = open_url ( self . _url + path , data = data , * * url_kwargs )
except URLError as exc :
raise AnsibleConnectionFailure ( ' Could not connect to {0} : {1} ' . format ( self . _url , exc . reason ) )
self . _auth = response . info ( ) . get ( ' Set-Cookie ' )
return response