2017-12-14 22:16:28 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright: (c) 2017, F5 Networks Inc.
|
|
|
|
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2018-06-20 19:16:43 +00:00
|
|
|
'status': ['stableinterface'],
|
2018-10-12 15:57:28 +00:00
|
|
|
'supported_by': 'certified'}
|
2017-12-14 22:16:28 +00:00
|
|
|
|
|
|
|
DOCUMENTATION = r'''
|
|
|
|
---
|
|
|
|
module: bigip_device_httpd
|
|
|
|
short_description: Manage HTTPD related settings on BIG-IP
|
|
|
|
description:
|
|
|
|
- Manages HTTPD related settings on the BIG-IP. These settings are interesting
|
|
|
|
to change when you want to set GUI timeouts and other TMUI related settings.
|
2018-05-10 17:59:49 +00:00
|
|
|
version_added: 2.5
|
2017-12-14 22:16:28 +00:00
|
|
|
options:
|
2018-01-04 04:58:22 +00:00
|
|
|
allow:
|
|
|
|
description:
|
|
|
|
- Specifies, if you have enabled HTTPD access, the IP address or address
|
|
|
|
range for other systems that can communicate with this system.
|
2018-05-12 00:12:17 +00:00
|
|
|
- To specify all addresses, use the value C(all).
|
|
|
|
- IP address can be specified, such as 172.27.1.10.
|
|
|
|
- IP rangees can be specified, such as 172.27.*.* or 172.27.0.0/255.255.0.0.
|
2017-12-14 22:16:28 +00:00
|
|
|
auth_name:
|
|
|
|
description:
|
2018-01-04 04:58:22 +00:00
|
|
|
- Sets the BIG-IP authentication realm name.
|
2017-12-14 22:16:28 +00:00
|
|
|
auth_pam_idle_timeout:
|
|
|
|
description:
|
|
|
|
- Sets the GUI timeout for automatic logout, in seconds.
|
|
|
|
auth_pam_validate_ip:
|
|
|
|
description:
|
|
|
|
- Sets the authPamValidateIp setting.
|
2018-01-12 20:08:49 +00:00
|
|
|
type: bool
|
2017-12-14 22:16:28 +00:00
|
|
|
auth_pam_dashboard_timeout:
|
|
|
|
description:
|
|
|
|
- Sets whether or not the BIG-IP dashboard will timeout.
|
2018-01-12 20:08:49 +00:00
|
|
|
type: bool
|
2017-12-14 22:16:28 +00:00
|
|
|
fast_cgi_timeout:
|
|
|
|
description:
|
|
|
|
- Sets the timeout of FastCGI.
|
|
|
|
hostname_lookup:
|
|
|
|
description:
|
|
|
|
- Sets whether or not to display the hostname, if possible.
|
2018-01-12 20:08:49 +00:00
|
|
|
type: bool
|
2017-12-14 22:16:28 +00:00
|
|
|
log_level:
|
|
|
|
description:
|
|
|
|
- Sets the minimum httpd log level.
|
|
|
|
choices: ['alert', 'crit', 'debug', 'emerg', 'error', 'info', 'notice', 'warn']
|
|
|
|
max_clients:
|
|
|
|
description:
|
|
|
|
- Sets the maximum number of clients that can connect to the GUI at once.
|
|
|
|
redirect_http_to_https:
|
|
|
|
description:
|
|
|
|
- Whether or not to redirect http requests to the GUI to https.
|
2018-01-12 20:08:49 +00:00
|
|
|
type: bool
|
2017-12-14 22:16:28 +00:00
|
|
|
ssl_port:
|
|
|
|
description:
|
|
|
|
- The HTTPS port to listen on.
|
2018-05-10 17:59:49 +00:00
|
|
|
ssl_cipher_suite:
|
|
|
|
description:
|
|
|
|
- Specifies the ciphers that the system uses.
|
|
|
|
- The values in the suite are separated by colons (:).
|
|
|
|
- Can be specified in either a string or list form. The list form is the
|
|
|
|
recommended way to provide the cipher suite. See examples for usage.
|
|
|
|
- Use the value C(default) to set the cipher suite to the system default.
|
|
|
|
This value is equivalent to specifying a list of C(ECDHE-RSA-AES128-GCM-SHA256,
|
|
|
|
ECDHE-RSA-AES256-GCM-SHA384,ECDHE-RSA-AES128-SHA,ECDHE-RSA-AES256-SHA,
|
|
|
|
ECDHE-RSA-AES128-SHA256,ECDHE-RSA-AES256-SHA384,ECDHE-ECDSA-AES128-GCM-SHA256,
|
|
|
|
ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-ECDSA-AES128-SHA,ECDHE-ECDSA-AES256-SHA,
|
|
|
|
ECDHE-ECDSA-AES128-SHA256,ECDHE-ECDSA-AES256-SHA384,AES128-GCM-SHA256,
|
|
|
|
AES256-GCM-SHA384,AES128-SHA,AES256-SHA,AES128-SHA256,AES256-SHA256,
|
|
|
|
ECDHE-RSA-DES-CBC3-SHA,ECDHE-ECDSA-DES-CBC3-SHA,DES-CBC3-SHA).
|
|
|
|
version_added: 2.6
|
|
|
|
ssl_protocols:
|
|
|
|
description:
|
|
|
|
- The list of SSL protocols to accept on the management console.
|
|
|
|
- A space-separated list of tokens in the format accepted by the Apache
|
|
|
|
mod_ssl SSLProtocol directive.
|
|
|
|
- Can be specified in either a string or list form. The list form is the
|
|
|
|
recommended way to provide the cipher suite. See examples for usage.
|
|
|
|
- Use the value C(default) to set the SSL protocols to the system default.
|
|
|
|
This value is equivalent to specifying a list of C(all,-SSLv2,-SSLv3).
|
|
|
|
version_added: 2.6
|
2017-12-14 22:16:28 +00:00
|
|
|
notes:
|
|
|
|
- Requires the requests Python package on the host. This is as easy as
|
2018-01-12 20:08:49 +00:00
|
|
|
C(pip install requests).
|
2017-12-14 22:16:28 +00:00
|
|
|
requirements:
|
|
|
|
- requests
|
|
|
|
extends_documentation_fragment: f5
|
|
|
|
author:
|
|
|
|
- Joe Reifel (@JoeReifel)
|
|
|
|
- Tim Rupp (@caphrim007)
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = r'''
|
|
|
|
- name: Set the BIG-IP authentication realm name
|
|
|
|
bigip_device_httpd:
|
|
|
|
auth_name: BIG-IP
|
2018-11-10 19:40:18 +00:00
|
|
|
provider:
|
|
|
|
password: secret
|
|
|
|
server: lb.mydomain.com
|
|
|
|
user: admin
|
2017-12-14 22:16:28 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Set the auth pam timeout to 3600 seconds
|
|
|
|
bigip_device_httpd:
|
|
|
|
auth_pam_idle_timeout: 1200
|
2018-11-10 19:40:18 +00:00
|
|
|
provider:
|
|
|
|
password: secret
|
|
|
|
server: lb.mydomain.com
|
|
|
|
user: admin
|
2017-12-14 22:16:28 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Set the validate IP settings
|
|
|
|
bigip_device_httpd:
|
|
|
|
auth_pam_validate_ip: on
|
2018-11-10 19:40:18 +00:00
|
|
|
provider:
|
|
|
|
password: secret
|
|
|
|
server: lb.mydomain.com
|
|
|
|
user: admin
|
2017-12-14 22:16:28 +00:00
|
|
|
delegate_to: localhost
|
2018-05-10 17:59:49 +00:00
|
|
|
|
|
|
|
- name: Set SSL cipher suite by list
|
|
|
|
bigip_device_httpd:
|
|
|
|
ssl_cipher_suite:
|
|
|
|
- ECDHE-RSA-AES128-GCM-SHA256
|
|
|
|
- ECDHE-RSA-AES256-GCM-SHA384
|
|
|
|
- ECDHE-RSA-AES128-SHA
|
|
|
|
- AES256-SHA256
|
2018-11-10 19:40:18 +00:00
|
|
|
provider:
|
|
|
|
password: secret
|
|
|
|
server: lb.mydomain.com
|
|
|
|
user: admin
|
2018-05-10 17:59:49 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Set SSL cipher suite by string
|
|
|
|
bigip_device_httpd:
|
|
|
|
ssl_cipher_suite: ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA:AES256-SHA256
|
2018-11-10 19:40:18 +00:00
|
|
|
provider:
|
|
|
|
password: secret
|
|
|
|
server: lb.mydomain.com
|
|
|
|
user: admin
|
2018-05-10 17:59:49 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Set SSL protocols by list
|
|
|
|
bigip_device_httpd:
|
|
|
|
ssl_protocols:
|
|
|
|
- all
|
|
|
|
- -SSLv2
|
|
|
|
- -SSLv3
|
2018-11-10 19:40:18 +00:00
|
|
|
provider:
|
|
|
|
password: secret
|
|
|
|
server: lb.mydomain.com
|
|
|
|
user: admin
|
2018-05-10 17:59:49 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Set SSL protocols by string
|
|
|
|
bigip_device_httpd:
|
2018-11-10 19:40:18 +00:00
|
|
|
ssl_protocols: all -SSLv2 -SSLv3
|
|
|
|
provider:
|
|
|
|
password: secret
|
|
|
|
server: lb.mydomain.com
|
|
|
|
user: admin
|
2018-05-10 17:59:49 +00:00
|
|
|
delegate_to: localhost
|
2017-12-14 22:16:28 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
RETURN = r'''
|
|
|
|
auth_pam_idle_timeout:
|
|
|
|
description: The new number of seconds for GUI timeout.
|
|
|
|
returned: changed
|
|
|
|
type: string
|
|
|
|
sample: 1200
|
2018-01-04 04:58:22 +00:00
|
|
|
auth_name:
|
|
|
|
description: The new authentication realm name.
|
|
|
|
returned: changed
|
|
|
|
type: string
|
|
|
|
sample: 'foo'
|
|
|
|
auth_pam_validate_ip:
|
|
|
|
description: The new authPamValidateIp setting.
|
|
|
|
returned: changed
|
|
|
|
type: bool
|
|
|
|
sample: on
|
|
|
|
auth_pam_dashboard_timeout:
|
|
|
|
description: Whether or not the BIG-IP dashboard will timeout.
|
|
|
|
returned: changed
|
|
|
|
type: bool
|
|
|
|
sample: off
|
|
|
|
fast_cgi_timeout:
|
|
|
|
description: The new timeout of FastCGI.
|
|
|
|
returned: changed
|
|
|
|
type: int
|
|
|
|
sample: 500
|
|
|
|
hostname_lookup:
|
|
|
|
description: Whether or not to display the hostname, if possible.
|
|
|
|
returned: changed
|
|
|
|
type: bool
|
|
|
|
sample: on
|
|
|
|
log_level:
|
|
|
|
description: The new minimum httpd log level.
|
|
|
|
returned: changed
|
|
|
|
type: string
|
|
|
|
sample: crit
|
|
|
|
max_clients:
|
|
|
|
description: The new maximum number of clients that can connect to the GUI at once.
|
|
|
|
returned: changed
|
|
|
|
type: int
|
|
|
|
sample: 20
|
|
|
|
redirect_http_to_https:
|
|
|
|
description: Whether or not to redirect http requests to the GUI to https.
|
|
|
|
returned: changed
|
|
|
|
type: bool
|
|
|
|
sample: on
|
|
|
|
ssl_port:
|
|
|
|
description: The new HTTPS port to listen on.
|
|
|
|
returned: changed
|
|
|
|
type: int
|
|
|
|
sample: 10443
|
2018-05-10 17:59:49 +00:00
|
|
|
ssl_cipher_suite:
|
|
|
|
description: The new ciphers that the system uses.
|
|
|
|
returned: changed
|
|
|
|
type: string
|
|
|
|
sample: ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA
|
2018-11-10 19:40:18 +00:00
|
|
|
ssl_cipher_suite_list:
|
|
|
|
description: List of the new ciphers that the system uses.
|
|
|
|
returned: changed
|
|
|
|
type: string
|
|
|
|
sample: ['ECDHE-RSA-AES256-GCM-SHA384', 'ECDHE-RSA-AES128-SHA']
|
2018-05-10 17:59:49 +00:00
|
|
|
ssl_protocols:
|
|
|
|
description: The new list of SSL protocols to accept on the management console.
|
|
|
|
returned: changed
|
|
|
|
type: string
|
|
|
|
sample: all -SSLv2 -SSLv3
|
2017-12-14 22:16:28 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
2018-01-12 20:08:49 +00:00
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
2018-05-10 17:59:49 +00:00
|
|
|
from ansible.module_utils.six import string_types
|
2017-12-14 22:16:28 +00:00
|
|
|
|
|
|
|
try:
|
2018-08-21 22:01:52 +00:00
|
|
|
from library.module_utils.network.f5.bigip import F5RestClient
|
2018-01-12 20:08:49 +00:00
|
|
|
from library.module_utils.network.f5.common import F5ModuleError
|
|
|
|
from library.module_utils.network.f5.common import AnsibleF5Parameters
|
|
|
|
from library.module_utils.network.f5.common import cleanup_tokens
|
|
|
|
from library.module_utils.network.f5.common import f5_argument_spec
|
2018-08-21 22:01:52 +00:00
|
|
|
from library.module_utils.network.f5.common import exit_json
|
|
|
|
from library.module_utils.network.f5.common import fail_json
|
2017-12-14 22:16:28 +00:00
|
|
|
except ImportError:
|
2018-08-21 22:01:52 +00:00
|
|
|
from ansible.module_utils.network.f5.bigip import F5RestClient
|
2018-01-12 20:08:49 +00:00
|
|
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
|
|
|
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
|
|
|
|
from ansible.module_utils.network.f5.common import cleanup_tokens
|
|
|
|
from ansible.module_utils.network.f5.common import f5_argument_spec
|
2018-08-21 22:01:52 +00:00
|
|
|
from ansible.module_utils.network.f5.common import exit_json
|
|
|
|
from ansible.module_utils.network.f5.common import fail_json
|
2017-12-14 22:16:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Parameters(AnsibleF5Parameters):
|
|
|
|
api_map = {
|
|
|
|
'authPamIdleTimeout': 'auth_pam_idle_timeout',
|
|
|
|
'authPamValidateIp': 'auth_pam_validate_ip',
|
|
|
|
'authName': 'auth_name',
|
|
|
|
'authPamDashboardTimeout': 'auth_pam_dashboard_timeout',
|
|
|
|
'fastcgiTimeout': 'fast_cgi_timeout',
|
|
|
|
'hostnameLookup': 'hostname_lookup',
|
|
|
|
'logLevel': 'log_level',
|
|
|
|
'maxClients': 'max_clients',
|
|
|
|
'redirectHttpToHttps': 'redirect_http_to_https',
|
2018-05-10 17:59:49 +00:00
|
|
|
'sslPort': 'ssl_port',
|
|
|
|
'sslCiphersuite': 'ssl_cipher_suite',
|
|
|
|
'sslProtocol': 'ssl_protocols'
|
2017-12-14 22:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
api_attributes = [
|
|
|
|
'authPamIdleTimeout', 'authPamValidateIp', 'authName', 'authPamDashboardTimeout',
|
|
|
|
'fastcgiTimeout', 'hostnameLookup', 'logLevel', 'maxClients', 'sslPort',
|
2018-05-10 17:59:49 +00:00
|
|
|
'redirectHttpToHttps', 'allow', 'sslCiphersuite', 'sslProtocol'
|
2017-12-14 22:16:28 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
returnables = [
|
|
|
|
'auth_pam_idle_timeout', 'auth_pam_validate_ip', 'auth_name',
|
|
|
|
'auth_pam_dashboard_timeout', 'fast_cgi_timeout', 'hostname_lookup',
|
2018-01-04 04:58:22 +00:00
|
|
|
'log_level', 'max_clients', 'redirect_http_to_https', 'ssl_port',
|
2018-11-10 19:40:18 +00:00
|
|
|
'allow', 'ssl_cipher_suite', 'ssl_protocols', 'ssl_cipher_suite_list',
|
2017-12-14 22:16:28 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
updatables = [
|
|
|
|
'auth_pam_idle_timeout', 'auth_pam_validate_ip', 'auth_name',
|
|
|
|
'auth_pam_dashboard_timeout', 'fast_cgi_timeout', 'hostname_lookup',
|
2018-01-04 04:58:22 +00:00
|
|
|
'log_level', 'max_clients', 'redirect_http_to_https', 'ssl_port',
|
2018-05-10 17:59:49 +00:00
|
|
|
'allow', 'ssl_cipher_suite', 'ssl_protocols'
|
2017-12-14 22:16:28 +00:00
|
|
|
]
|
|
|
|
|
2018-05-10 17:59:49 +00:00
|
|
|
_ciphers = "ECDHE-RSA-AES128-GCM-SHA256:" \
|
|
|
|
"ECDHE-RSA-AES256-GCM-SHA384:" \
|
|
|
|
"ECDHE-RSA-AES128-SHA:" \
|
|
|
|
"ECDHE-RSA-AES256-SHA:" \
|
|
|
|
"ECDHE-RSA-AES128-SHA256:" \
|
|
|
|
"ECDHE-RSA-AES256-SHA384:" \
|
|
|
|
"ECDHE-ECDSA-AES128-GCM-SHA256:" \
|
|
|
|
"ECDHE-ECDSA-AES256-GCM-SHA384:" \
|
|
|
|
"ECDHE-ECDSA-AES128-SHA:" \
|
|
|
|
"ECDHE-ECDSA-AES256-SHA:" \
|
|
|
|
"ECDHE-ECDSA-AES128-SHA256:" \
|
|
|
|
"ECDHE-ECDSA-AES256-SHA384:" \
|
|
|
|
"AES128-GCM-SHA256:" \
|
|
|
|
"AES256-GCM-SHA384:" \
|
|
|
|
"AES128-SHA:" \
|
|
|
|
"AES256-SHA:" \
|
|
|
|
"AES128-SHA256:" \
|
|
|
|
"AES256-SHA256:" \
|
|
|
|
"ECDHE-RSA-DES-CBC3-SHA:" \
|
|
|
|
"ECDHE-ECDSA-DES-CBC3-SHA:" \
|
|
|
|
"DES-CBC3-SHA"
|
|
|
|
|
|
|
|
_protocols = 'all -SSLv2 -SSLv3'
|
|
|
|
|
2017-12-14 22:16:28 +00:00
|
|
|
@property
|
|
|
|
def auth_pam_idle_timeout(self):
|
|
|
|
if self._values['auth_pam_idle_timeout'] is None:
|
|
|
|
return None
|
|
|
|
return int(self._values['auth_pam_idle_timeout'])
|
|
|
|
|
|
|
|
@property
|
|
|
|
def fast_cgi_timeout(self):
|
|
|
|
if self._values['fast_cgi_timeout'] is None:
|
|
|
|
return None
|
|
|
|
return int(self._values['fast_cgi_timeout'])
|
|
|
|
|
|
|
|
@property
|
|
|
|
def max_clients(self):
|
|
|
|
if self._values['max_clients'] is None:
|
|
|
|
return None
|
|
|
|
return int(self._values['max_clients'])
|
|
|
|
|
|
|
|
@property
|
|
|
|
def ssl_port(self):
|
|
|
|
if self._values['ssl_port'] is None:
|
|
|
|
return None
|
|
|
|
return int(self._values['ssl_port'])
|
|
|
|
|
|
|
|
|
|
|
|
class ModuleParameters(Parameters):
|
|
|
|
@property
|
|
|
|
def auth_pam_validate_ip(self):
|
|
|
|
if self._values['auth_pam_validate_ip'] is None:
|
|
|
|
return None
|
|
|
|
if self._values['auth_pam_validate_ip']:
|
|
|
|
return "on"
|
|
|
|
return "off"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def auth_pam_dashboard_timeout(self):
|
|
|
|
if self._values['auth_pam_dashboard_timeout'] is None:
|
|
|
|
return None
|
|
|
|
if self._values['auth_pam_dashboard_timeout']:
|
|
|
|
return "on"
|
|
|
|
return "off"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def hostname_lookup(self):
|
|
|
|
if self._values['hostname_lookup'] is None:
|
|
|
|
return None
|
|
|
|
if self._values['hostname_lookup']:
|
|
|
|
return "on"
|
|
|
|
return "off"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def redirect_http_to_https(self):
|
|
|
|
if self._values['redirect_http_to_https'] is None:
|
|
|
|
return None
|
|
|
|
if self._values['redirect_http_to_https']:
|
|
|
|
return "enabled"
|
|
|
|
return "disabled"
|
|
|
|
|
2018-01-04 04:58:22 +00:00
|
|
|
@property
|
|
|
|
def allow(self):
|
|
|
|
if self._values['allow'] is None:
|
|
|
|
return None
|
|
|
|
if self._values['allow'][0] == 'all':
|
|
|
|
return 'all'
|
|
|
|
if self._values['allow'][0] == '':
|
|
|
|
return ''
|
|
|
|
allow = self._values['allow']
|
|
|
|
result = list(set([str(x) for x in allow]))
|
|
|
|
result = sorted(result)
|
|
|
|
return result
|
|
|
|
|
2018-05-10 17:59:49 +00:00
|
|
|
@property
|
|
|
|
def ssl_cipher_suite(self):
|
|
|
|
if self._values['ssl_cipher_suite'] is None:
|
|
|
|
return None
|
|
|
|
if isinstance(self._values['ssl_cipher_suite'], string_types):
|
|
|
|
ciphers = self._values['ssl_cipher_suite'].strip()
|
|
|
|
else:
|
|
|
|
ciphers = self._values['ssl_cipher_suite']
|
|
|
|
if not ciphers:
|
|
|
|
raise F5ModuleError(
|
|
|
|
"ssl_cipher_suite may not be set to 'none'"
|
|
|
|
)
|
|
|
|
if ciphers == 'default':
|
2018-11-10 19:40:18 +00:00
|
|
|
ciphers = ':'.join(Parameters._ciphers.split(':'))
|
2018-05-10 17:59:49 +00:00
|
|
|
elif isinstance(self._values['ssl_cipher_suite'], string_types):
|
2018-11-10 19:40:18 +00:00
|
|
|
ciphers = ':'.join(ciphers.split(':'))
|
2018-05-10 17:59:49 +00:00
|
|
|
else:
|
2018-11-10 19:40:18 +00:00
|
|
|
ciphers = ':'.join(ciphers)
|
2018-05-10 17:59:49 +00:00
|
|
|
return ciphers
|
|
|
|
|
|
|
|
@property
|
|
|
|
def ssl_protocols(self):
|
|
|
|
if self._values['ssl_protocols'] is None:
|
|
|
|
return None
|
|
|
|
if isinstance(self._values['ssl_protocols'], string_types):
|
|
|
|
protocols = self._values['ssl_protocols'].strip()
|
|
|
|
else:
|
|
|
|
protocols = self._values['ssl_protocols']
|
|
|
|
if not protocols:
|
|
|
|
raise F5ModuleError(
|
|
|
|
"ssl_protocols may not be set to 'none'"
|
|
|
|
)
|
|
|
|
if protocols == 'default':
|
|
|
|
protocols = ' '.join(sorted(Parameters._protocols.split(' ')))
|
|
|
|
elif isinstance(protocols, string_types):
|
|
|
|
protocols = ' '.join(sorted(protocols.split(' ')))
|
|
|
|
else:
|
|
|
|
protocols = ' '.join(sorted(protocols))
|
|
|
|
return protocols
|
|
|
|
|
2017-12-14 22:16:28 +00:00
|
|
|
|
|
|
|
class ApiParameters(Parameters):
|
2018-01-04 04:58:22 +00:00
|
|
|
@property
|
|
|
|
def allow(self):
|
|
|
|
if self._values['allow'] is None:
|
|
|
|
return ''
|
|
|
|
if self._values['allow'][0] == 'All':
|
|
|
|
return 'all'
|
|
|
|
allow = self._values['allow']
|
|
|
|
result = list(set([str(x) for x in allow]))
|
|
|
|
result = sorted(result)
|
|
|
|
return result
|
2017-12-14 22:16:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Changes(Parameters):
|
|
|
|
def to_return(self):
|
|
|
|
result = {}
|
|
|
|
try:
|
|
|
|
for returnable in self.returnables:
|
|
|
|
result[returnable] = getattr(self, returnable)
|
|
|
|
result = self._filter_params(result)
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
class UsableChanges(Changes):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class ReportableChanges(Changes):
|
2018-05-10 17:59:49 +00:00
|
|
|
@property
|
|
|
|
def ssl_cipher_suite(self):
|
2018-11-10 19:40:18 +00:00
|
|
|
default = ':'.join(Parameters._ciphers.split(':'))
|
2018-05-10 17:59:49 +00:00
|
|
|
if self._values['ssl_cipher_suite'] == default:
|
|
|
|
return 'default'
|
|
|
|
else:
|
|
|
|
return self._values['ssl_cipher_suite']
|
|
|
|
|
2018-11-10 19:40:18 +00:00
|
|
|
@property
|
|
|
|
def ssl_cipher_suite_list(self):
|
|
|
|
return self._values['ssl_cipher_suite'].split(':')
|
|
|
|
|
2018-05-10 17:59:49 +00:00
|
|
|
@property
|
|
|
|
def ssl_protocols(self):
|
|
|
|
default = ' '.join(sorted(Parameters._protocols.split(' ')))
|
|
|
|
if self._values['ssl_protocols'] == default:
|
|
|
|
return 'default'
|
|
|
|
else:
|
|
|
|
return self._values['ssl_protocols']
|
2017-12-14 22:16:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Difference(object):
|
|
|
|
def __init__(self, want, have=None):
|
|
|
|
self.want = want
|
|
|
|
self.have = have
|
|
|
|
|
|
|
|
def compare(self, param):
|
|
|
|
try:
|
|
|
|
result = getattr(self, param)
|
|
|
|
return result
|
|
|
|
except AttributeError:
|
|
|
|
return self.__default(param)
|
|
|
|
|
|
|
|
def __default(self, param):
|
|
|
|
attr1 = getattr(self.want, param)
|
|
|
|
try:
|
|
|
|
attr2 = getattr(self.have, param)
|
|
|
|
if attr1 != attr2:
|
|
|
|
return attr1
|
|
|
|
except AttributeError:
|
|
|
|
return attr1
|
|
|
|
|
2018-01-04 04:58:22 +00:00
|
|
|
@property
|
|
|
|
def allow(self):
|
|
|
|
if self.want.allow is None:
|
|
|
|
return None
|
|
|
|
if self.want.allow == 'all' and self.have.allow == 'all':
|
|
|
|
return None
|
|
|
|
if self.want.allow == 'all':
|
|
|
|
return ['All']
|
|
|
|
if self.want.allow == '' and self.have.allow == '':
|
|
|
|
return None
|
|
|
|
if self.want.allow == '':
|
|
|
|
return []
|
|
|
|
if self.want.allow != self.have.allow:
|
|
|
|
return self.want.allow
|
|
|
|
|
2017-12-14 22:16:28 +00:00
|
|
|
|
|
|
|
class ModuleManager(object):
|
2018-01-12 20:08:49 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.module = kwargs.get('module', None)
|
|
|
|
self.client = kwargs.get('client', None)
|
|
|
|
self.want = ModuleParameters(params=self.module.params)
|
2017-12-14 22:16:28 +00:00
|
|
|
self.have = ApiParameters()
|
|
|
|
self.changes = UsableChanges()
|
|
|
|
|
|
|
|
def _set_changed_options(self):
|
|
|
|
changed = {}
|
|
|
|
for key in Parameters.returnables:
|
|
|
|
if getattr(self.want, key) is not None:
|
|
|
|
changed[key] = getattr(self.want, key)
|
|
|
|
if changed:
|
2018-01-12 20:08:49 +00:00
|
|
|
self.changes = Changes(params=changed)
|
2017-12-14 22:16:28 +00:00
|
|
|
|
|
|
|
def _update_changed_options(self):
|
|
|
|
diff = Difference(self.want, self.have)
|
|
|
|
updatables = Parameters.updatables
|
|
|
|
changed = dict()
|
|
|
|
for k in updatables:
|
|
|
|
change = diff.compare(k)
|
|
|
|
if change is None:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if isinstance(change, dict):
|
|
|
|
changed.update(change)
|
|
|
|
else:
|
|
|
|
changed[k] = change
|
|
|
|
if changed:
|
2018-01-12 20:08:49 +00:00
|
|
|
self.changes = UsableChanges(params=changed)
|
2017-12-14 22:16:28 +00:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def should_update(self):
|
|
|
|
result = self._update_changed_options()
|
|
|
|
if result:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def exec_module(self):
|
|
|
|
result = dict()
|
|
|
|
|
2018-08-21 22:01:52 +00:00
|
|
|
changed = self.present()
|
2017-12-14 22:16:28 +00:00
|
|
|
|
2018-01-12 20:08:49 +00:00
|
|
|
reportable = ReportableChanges(params=self.changes.to_return())
|
2017-12-14 22:16:28 +00:00
|
|
|
changes = reportable.to_return()
|
|
|
|
result.update(**changes)
|
|
|
|
result.update(dict(changed=changed))
|
|
|
|
self._announce_deprecations(result)
|
|
|
|
return result
|
|
|
|
|
|
|
|
def _announce_deprecations(self, result):
|
|
|
|
warnings = result.pop('__warnings', [])
|
|
|
|
for warning in warnings:
|
2018-01-12 20:08:49 +00:00
|
|
|
self.module.deprecate(
|
2017-12-14 22:16:28 +00:00
|
|
|
msg=warning['msg'],
|
|
|
|
version=warning['version']
|
|
|
|
)
|
|
|
|
|
|
|
|
def present(self):
|
|
|
|
return self.update()
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
self.have = self.read_current_from_device()
|
|
|
|
if not self.should_update():
|
|
|
|
return False
|
2018-01-12 20:08:49 +00:00
|
|
|
if self.module.check_mode:
|
2017-12-14 22:16:28 +00:00
|
|
|
return True
|
|
|
|
self.update_on_device()
|
|
|
|
return True
|
|
|
|
|
|
|
|
def update_on_device(self):
|
|
|
|
params = self.changes.api_params()
|
2018-08-21 22:01:52 +00:00
|
|
|
uri = "https://{0}:{1}/mgmt/tm/sys/httpd".format(
|
|
|
|
self.client.provider['server'],
|
|
|
|
self.client.provider['server_port']
|
|
|
|
)
|
|
|
|
|
2017-12-14 22:16:28 +00:00
|
|
|
try:
|
2018-08-21 22:01:52 +00:00
|
|
|
resp = self.client.api.patch(uri, json=params)
|
|
|
|
try:
|
|
|
|
response = resp.json()
|
|
|
|
except ValueError as ex:
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
if 'message' in response:
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
else:
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
except Exception as ex:
|
|
|
|
valid = [
|
|
|
|
'Remote end closed connection',
|
|
|
|
'Connection aborted',
|
|
|
|
]
|
Network F5: Adjust for Python 3 scoping rules (#37554)
This PR makes and adjustment for Python 3 scoping rules which differ from Python 2. In Python 3, the variable __ex__ goes out of scope at the exit of the __try-except__ block. This means that when __ex__ is referred to on the lines that follow, it would be an _undefined name_ causing a __NameError__ to be raised instead of the expected __ConnectionError__.
flake8 testing of https://github.com/ansible/ansible on Python 3.6.3
The command "echo ; echo -n "flake8 testing of ${URL} on " ; python -V" exited with 0.
130.72s$ time flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
./lib/ansible/module_utils/api.py:114:21: F823 local variable 'retry_count' (defined in enclosing scope on line 107) referenced before assignment
retry_count += 1 # pylint: disable=undefined-variable
^
./lib/ansible/module_utils/six/__init__.py:54:20: F821 undefined name 'basestring'
string_types = basestring,
^
./lib/ansible/module_utils/six/__init__.py:55:27: F821 undefined name 'long'
integer_types = (int, long)
^
./lib/ansible/module_utils/six/__init__.py:57:17: F821 undefined name 'unicode'
text_type = unicode
^
./lib/ansible/module_utils/six/__init__.py:658:16: F821 undefined name 'unicode'
return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
^
./lib/ansible/module_utils/six/__init__.py:754:37: F821 undefined name 'basestring'
if not isinstance(data, basestring):
^
./lib/ansible/module_utils/six/__init__.py:757:32: F821 undefined name 'file'
if (isinstance(fp, file) and
^
./lib/ansible/module_utils/six/__init__.py:758:38: F821 undefined name 'unicode'
isinstance(data, unicode) and
^
./lib/ansible/module_utils/six/__init__.py:768:32: F821 undefined name 'unicode'
if isinstance(sep, unicode):
^
./lib/ansible/module_utils/six/__init__.py:774:32: F821 undefined name 'unicode'
if isinstance(end, unicode):
^
./lib/ansible/module_utils/six/__init__.py:782:36: F821 undefined name 'unicode'
if isinstance(arg, unicode):
^
./lib/ansible/module_utils/six/__init__.py:786:23: F821 undefined name 'unicode'
newline = unicode("\n")
^
./lib/ansible/module_utils/six/__init__.py:787:21: F821 undefined name 'unicode'
space = unicode(" ")
^
./lib/ansible/modules/cloud/misc/rhevm.py:594:24: F821 undefined name 'e'
setMsg(str(e))
^
./lib/ansible/modules/cloud/openstack/os_user.py:202:38: F821 undefined name 'shade'
if description and StrictVersion(shade.__version__) < StrictVersion('1.13.0'):
^
./lib/ansible/modules/cloud/openstack/os_volume.py:153:27: F821 undefined name 'shade'
StrictVersion(shade.__version__) < StrictVersion('1.22')):
^
./lib/ansible/modules/files/archive.py:391:92: F821 undefined name 'e'
module.fail_json(dest=dest, msg='Error deleting some source files: ' + str(e), files=errors)
^
./lib/ansible/modules/network/dellos9/dellos9_facts.py:379:24: F821 undefined name 'key'
parsed[key] += '\n%s' % line
^
./lib/ansible/modules/network/dellos9/dellos9_facts.py:399:24: F821 undefined name 'key'
parsed[key] += '\n%s' % line
^
./lib/ansible/modules/network/dellos9/dellos9_facts.py:403:24: F821 undefined name 'key'
parsed[key] += '\n%s' % line
^
./lib/ansible/modules/network/dellos9/dellos9_facts.py:418:24: F821 undefined name 'key'
parsed[key] += '\n%s' % line
^
./lib/ansible/modules/network/f5/bigip_device_httpd.py:461:40: F821 undefined name 'ex'
if 'Connection aborted' in str(ex) and 'redirectHttpToHttps' in params:
^
./lib/ansible/modules/network/f5/bigip_device_httpd.py:465:33: F821 undefined name 'ex'
raise F5ModuleError(str(ex))
^
./lib/ansible/modules/network/ironware/ironware_facts.py:274:24: F821 undefined name 'key'
parsed[key] += '\n%s' % line
^
./lib/ansible/modules/network/ironware/ironware_facts.py:514:24: F821 undefined name 'key'
parsed[key] += '\n%s' % line
^
24 F821 undefined name 'basestring'
1 F823 local variable 'retry_count' (defined in enclosing scope on line 107) referenced before assignment
25
2018-03-18 02:19:43 +00:00
|
|
|
# BIG-IP will kill your management connection when you change the HTTP
|
|
|
|
# redirect setting. So this catches that and handles it gracefully.
|
2018-08-21 22:01:52 +00:00
|
|
|
if 'redirectHttpToHttps' in params:
|
|
|
|
if any(i for i in valid if i in str(ex)):
|
|
|
|
# Wait for BIG-IP web server to settle after changing this
|
|
|
|
time.sleep(2)
|
|
|
|
return True
|
Network F5: Adjust for Python 3 scoping rules (#37554)
This PR makes and adjustment for Python 3 scoping rules which differ from Python 2. In Python 3, the variable __ex__ goes out of scope at the exit of the __try-except__ block. This means that when __ex__ is referred to on the lines that follow, it would be an _undefined name_ causing a __NameError__ to be raised instead of the expected __ConnectionError__.
flake8 testing of https://github.com/ansible/ansible on Python 3.6.3
The command "echo ; echo -n "flake8 testing of ${URL} on " ; python -V" exited with 0.
130.72s$ time flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
./lib/ansible/module_utils/api.py:114:21: F823 local variable 'retry_count' (defined in enclosing scope on line 107) referenced before assignment
retry_count += 1 # pylint: disable=undefined-variable
^
./lib/ansible/module_utils/six/__init__.py:54:20: F821 undefined name 'basestring'
string_types = basestring,
^
./lib/ansible/module_utils/six/__init__.py:55:27: F821 undefined name 'long'
integer_types = (int, long)
^
./lib/ansible/module_utils/six/__init__.py:57:17: F821 undefined name 'unicode'
text_type = unicode
^
./lib/ansible/module_utils/six/__init__.py:658:16: F821 undefined name 'unicode'
return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape")
^
./lib/ansible/module_utils/six/__init__.py:754:37: F821 undefined name 'basestring'
if not isinstance(data, basestring):
^
./lib/ansible/module_utils/six/__init__.py:757:32: F821 undefined name 'file'
if (isinstance(fp, file) and
^
./lib/ansible/module_utils/six/__init__.py:758:38: F821 undefined name 'unicode'
isinstance(data, unicode) and
^
./lib/ansible/module_utils/six/__init__.py:768:32: F821 undefined name 'unicode'
if isinstance(sep, unicode):
^
./lib/ansible/module_utils/six/__init__.py:774:32: F821 undefined name 'unicode'
if isinstance(end, unicode):
^
./lib/ansible/module_utils/six/__init__.py:782:36: F821 undefined name 'unicode'
if isinstance(arg, unicode):
^
./lib/ansible/module_utils/six/__init__.py:786:23: F821 undefined name 'unicode'
newline = unicode("\n")
^
./lib/ansible/module_utils/six/__init__.py:787:21: F821 undefined name 'unicode'
space = unicode(" ")
^
./lib/ansible/modules/cloud/misc/rhevm.py:594:24: F821 undefined name 'e'
setMsg(str(e))
^
./lib/ansible/modules/cloud/openstack/os_user.py:202:38: F821 undefined name 'shade'
if description and StrictVersion(shade.__version__) < StrictVersion('1.13.0'):
^
./lib/ansible/modules/cloud/openstack/os_volume.py:153:27: F821 undefined name 'shade'
StrictVersion(shade.__version__) < StrictVersion('1.22')):
^
./lib/ansible/modules/files/archive.py:391:92: F821 undefined name 'e'
module.fail_json(dest=dest, msg='Error deleting some source files: ' + str(e), files=errors)
^
./lib/ansible/modules/network/dellos9/dellos9_facts.py:379:24: F821 undefined name 'key'
parsed[key] += '\n%s' % line
^
./lib/ansible/modules/network/dellos9/dellos9_facts.py:399:24: F821 undefined name 'key'
parsed[key] += '\n%s' % line
^
./lib/ansible/modules/network/dellos9/dellos9_facts.py:403:24: F821 undefined name 'key'
parsed[key] += '\n%s' % line
^
./lib/ansible/modules/network/dellos9/dellos9_facts.py:418:24: F821 undefined name 'key'
parsed[key] += '\n%s' % line
^
./lib/ansible/modules/network/f5/bigip_device_httpd.py:461:40: F821 undefined name 'ex'
if 'Connection aborted' in str(ex) and 'redirectHttpToHttps' in params:
^
./lib/ansible/modules/network/f5/bigip_device_httpd.py:465:33: F821 undefined name 'ex'
raise F5ModuleError(str(ex))
^
./lib/ansible/modules/network/ironware/ironware_facts.py:274:24: F821 undefined name 'key'
parsed[key] += '\n%s' % line
^
./lib/ansible/modules/network/ironware/ironware_facts.py:514:24: F821 undefined name 'key'
parsed[key] += '\n%s' % line
^
24 F821 undefined name 'basestring'
1 F823 local variable 'retry_count' (defined in enclosing scope on line 107) referenced before assignment
25
2018-03-18 02:19:43 +00:00
|
|
|
raise F5ModuleError(str(ex))
|
2017-12-14 22:16:28 +00:00
|
|
|
|
|
|
|
def read_current_from_device(self):
|
2018-08-21 22:01:52 +00:00
|
|
|
uri = "https://{0}:{1}/mgmt/tm/sys/httpd".format(
|
|
|
|
self.client.provider['server'],
|
|
|
|
self.client.provider['server_port']
|
|
|
|
)
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
try:
|
|
|
|
response = resp.json()
|
|
|
|
except ValueError as ex:
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
if 'message' in response:
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
else:
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
return ApiParameters(params=response)
|
2017-12-14 22:16:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ArgumentSpec(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.supports_check_mode = True
|
2018-01-12 20:08:49 +00:00
|
|
|
argument_spec = dict(
|
2018-01-04 04:58:22 +00:00
|
|
|
allow=dict(
|
|
|
|
type='list'
|
|
|
|
),
|
2017-12-14 22:16:28 +00:00
|
|
|
auth_name=dict(),
|
|
|
|
auth_pam_idle_timeout=dict(
|
|
|
|
type='int'
|
|
|
|
),
|
|
|
|
fast_cgi_timeout=dict(
|
|
|
|
type='int'
|
|
|
|
),
|
|
|
|
max_clients=dict(
|
|
|
|
type='int'
|
|
|
|
),
|
|
|
|
ssl_port=dict(
|
|
|
|
type='int'
|
|
|
|
),
|
|
|
|
auth_pam_validate_ip=dict(
|
|
|
|
type='bool'
|
|
|
|
),
|
|
|
|
auth_pam_dashboard_timeout=dict(
|
|
|
|
type='bool'
|
|
|
|
),
|
|
|
|
hostname_lookup=dict(
|
|
|
|
type='bool'
|
|
|
|
),
|
|
|
|
log_level=dict(
|
|
|
|
choices=[
|
|
|
|
'alert', 'crit', 'debug', 'emerg',
|
|
|
|
'error', 'info', 'notice', 'warn'
|
|
|
|
]
|
|
|
|
),
|
|
|
|
redirect_http_to_https=dict(
|
|
|
|
type='bool'
|
2018-05-10 17:59:49 +00:00
|
|
|
),
|
|
|
|
ssl_cipher_suite=dict(type='raw'),
|
|
|
|
ssl_protocols=dict(type='raw')
|
2017-12-14 22:16:28 +00:00
|
|
|
)
|
2018-01-12 20:08:49 +00:00
|
|
|
self.argument_spec = {}
|
|
|
|
self.argument_spec.update(f5_argument_spec)
|
|
|
|
self.argument_spec.update(argument_spec)
|
2017-12-14 22:16:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
spec = ArgumentSpec()
|
|
|
|
|
2018-01-12 20:08:49 +00:00
|
|
|
module = AnsibleModule(
|
2017-12-14 22:16:28 +00:00
|
|
|
argument_spec=spec.argument_spec,
|
2018-08-21 22:01:52 +00:00
|
|
|
supports_check_mode=spec.supports_check_mode,
|
2017-12-14 22:16:28 +00:00
|
|
|
)
|
|
|
|
|
2018-11-10 19:40:18 +00:00
|
|
|
client = F5RestClient(**module.params)
|
|
|
|
|
2017-12-14 22:16:28 +00:00
|
|
|
try:
|
2018-01-12 20:08:49 +00:00
|
|
|
mm = ModuleManager(module=module, client=client)
|
2017-12-14 22:16:28 +00:00
|
|
|
results = mm.exec_module()
|
2018-09-13 19:26:17 +00:00
|
|
|
cleanup_tokens(client)
|
2018-08-21 22:01:52 +00:00
|
|
|
exit_json(module, results, client)
|
2018-01-12 20:08:49 +00:00
|
|
|
except F5ModuleError as ex:
|
2018-09-13 19:26:17 +00:00
|
|
|
cleanup_tokens(client)
|
2018-08-21 22:01:52 +00:00
|
|
|
fail_json(module, ex, client)
|
2017-12-14 22:16:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|