diff --git a/lib/ansible/module_utils/network/aci/aci.py b/lib/ansible/module_utils/network/aci/aci.py index c20fc028eb3..ba7e41e3c0f 100644 --- a/lib/ansible/module_utils/network/aci/aci.py +++ b/lib/ansible/module_utils/network/aci/aci.py @@ -64,6 +64,7 @@ except ImportError: def aci_argument_spec(): return dict( hostname=dict(type='str', required=True, aliases=['host']), + port=dict(type='int', required=False), username=dict(type='str', default='admin', aliases=['user']), password=dict(type='str', no_log=True), private_key=dict(type='path', aliases=['cert_key']), # Beware, this is not the same as client_key ! @@ -214,7 +215,10 @@ class ACIModule(object): ''' Log in to APIC ''' # Perform login request - url = '%(protocol)s://%(hostname)s/api/aaaLogin.json' % self.params + if 'port' in self.params and self.params['port'] is not None: + url = '%(protocol)s://%(hostname)s:%(port)s/api/aaaLogin.json' % self.params + else: + url = '%(protocol)s://%(hostname)s/api/aaaLogin.json' % self.params payload = {'aaaUser': {'attributes': {'name': self.params['username'], 'pwd': self.params['password']}}} resp, auth = fetch_url(self.module, url, data=json.dumps(payload), @@ -275,7 +279,11 @@ class ACIModule(object): # Ensure method is set (only do this once) self.define_method() self.result['path'] = path - self.result['url'] = '%(protocol)s://%(hostname)s/' % self.params + path.lstrip('/') + + if 'port' in self.params and self.params['port'] is not None: + self.result['url'] = '%(protocol)s://%(hostname)s:%(port)s/' % self.params + path.lstrip('/') + else: + self.result['url'] = '%(protocol)s://%(hostname)s/' % self.params + path.lstrip('/') # Sign and encode request as to APIC's wishes if self.params['private_key'] is not None: @@ -309,7 +317,11 @@ class ACIModule(object): # Ensure method is set self.result['path'] = path - self.result['url'] = '%(protocol)s://%(hostname)s/' % self.params + path.lstrip('/') + + if 'port' in self.params and self.params['port'] is not None: + self.result['url'] = '%(protocol)s://%(hostname)s:%(port)s/' % self.params + path.lstrip('/') + else: + self.result['url'] = '%(protocol)s://%(hostname)s/' % self.params + path.lstrip('/') # Sign and encode request as to APIC's wishes if self.params['private_key'] is not None: @@ -382,7 +394,10 @@ class ACIModule(object): path, filter_string = self._construct_url_1(root_class, child_includes) self.result['path'] = path - self.result['url'] = '{0}://{1}/{2}'.format(self.module.params['protocol'], self.module.params['hostname'], path) + if 'port' in self.params and self.params['port'] is not None: + self.result['url'] = '{0}://{1}:{2}/{3}'.format(self.module.params['protocol'], self.module.params['hostname'], self.module.params['port'], path) + else: + self.result['url'] = '{0}://{1}/{2}'.format(self.module.params['protocol'], self.module.params['hostname'], path) self.result['filter_string'] = filter_string def _construct_url_1(self, obj, child_includes): diff --git a/lib/ansible/utils/module_docs_fragments/aci.py b/lib/ansible/utils/module_docs_fragments/aci.py index 12c633ff96a..7a4676108e1 100644 --- a/lib/ansible/utils/module_docs_fragments/aci.py +++ b/lib/ansible/utils/module_docs_fragments/aci.py @@ -28,6 +28,11 @@ options: - IP Address or hostname of APIC resolvable by Ansible control host. required: yes aliases: [ host ] + port: + description: + - Port number to be used for REST connection. + default: 443 (for https) and 80 (for http) + type: int username: description: - The username to use for authentication.