mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 03:11:24 -07:00
* openstack: standardize tls params * tower: tower_verify_ssl->validate_certs * docker: use standard tls config params - cacert_path -> ca_cert - cert_path -> client_cert - key_path -> client_key - tls_verify -> validate_certs * k8s: standardize tls connection params - verify_ssl -> validate_certs - ssl_ca_cert -> ca_cert - cert_file -> client_cert - key_file -> client_key * ingate: verify_ssl -> validate_certs * manageiq: standardize tls params - verify_ssl -> validate_certs - ca_bundle_path -> ca_cert * mysql: standardize tls params - ssl_ca -> ca_cert - ssl_cert -> client_cert - ssl_key -> client_key * nios: ssl_verify -> validate_certs * postgresql: ssl_rootcert -> ca_cert * rabbitmq: standardize tls params - cacert -> ca_cert - cert -> client_cert - key -> client_key * rackspace: verify_ssl -> validate_certs * vca: verify_certs -> validate_certs * kubevirt_cdi_upload: upload_host_verify_ssl -> upload_host_validate_certs * lxd: standardize tls params - key_file -> client_key - cert_file -> client_cert * get_certificate: ca_certs -> ca_cert * get_certificate.py: clarify one or more certs in a file Co-Authored-By: jamescassell <code@james.cassell.me> * zabbix: tls_issuer -> ca_cert * bigip_device_auth_ldap: standardize tls params - ssl_check_peer -> validate_certs - ssl_client_cert -> client_cert - ssl_client_key -> client_key - ssl_ca_cert -> ca_cert * vdirect: vdirect_validate_certs -> validate_certs * mqtt: standardize tls params - ca_certs -> ca_cert - certfile -> client_cert - keyfile -> client_key * pulp_repo: standardize tls params remove `importer_ssl` prefix * rhn_register: sslcacert -> ca_cert * yum_repository: standardize tls params The fix for yum_repository is not straightforward since this module is only a thin wrapper for the underlying commands and config. In this case, we add the new values as aliases, keeping the old as primary, only due to the internal structure of the module. Aliases added: - sslcacert -> ca_cert - sslclientcert -> client_cert - sslclientkey -> client_key - sslverify -> validate_certs * gitlab_hook: enable_ssl_verification -> hook_validate_certs * Adjust arguments for docker_swarm inventory plugin. * foreman callback: standardize tls params - ssl_cert -> client_cert - ssl_key -> client_key * grafana_annotations: validate_grafana_certs -> validate_certs * nrdp callback: validate_nrdp_certs -> validate_certs * kubectl connection: standardize tls params - kubectl_cert_file -> client_cert - kubectl_key_file -> client_key - kubectl_ssl_ca_cert -> ca_cert - kubectl_verify_ssl -> validate_certs * oc connection: standardize tls params - oc_cert_file -> client_cert - oc_key_file -> client_key - oc_ssl_ca_cert -> ca_cert - oc_verify_ssl -> validate_certs * psrp connection: cert_trust_path -> ca_cert TODO: cert_validation -> validate_certs (multi-valued vs bool) * k8s inventory: standardize tls params - cert_file -> client_cert - key_file -> client_key - ca_cert -> ca_cert - verify_ssl -> validate_certs * openshift inventory: standardize tls params - cert_file -> client_cert - key_file -> client_key - ca_cert -> ca_cert - verify_ssl -> validate_certs * tower inventory: verify_ssl -> validate_certs * hashi_vault lookup: cacert -> ca_cert * k8s lookup: standardize tls params - cert_file -> client_cert - key_file -> client_key - ca_cert -> ca_cert - verify_ssl -> validate_certs * laps_passord lookup: cacert_file -> ca_cert * changelog for TLS parameter standardization
158 lines
6.7 KiB
Python
158 lines
6.7 KiB
Python
# This code is part of Ansible, but is an independent component.
|
|
# This particular file snippet, and this file snippet only, is BSD licensed.
|
|
# Modules you write using this snippet, which is embedded dynamically by Ansible
|
|
# still belong to the author of the module, and may assign their own license
|
|
# to the complete work.
|
|
#
|
|
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
|
# All rights reserved.
|
|
#
|
|
# Redistribution and use in source and binary forms, with or without modification,
|
|
# are permitted provided that the following conditions are met:
|
|
#
|
|
# * Redistributions of source code must retain the above copyright
|
|
# notice, this list of conditions and the following disclaimer.
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
# this list of conditions and the following disclaimer in the documentation
|
|
# and/or other materials provided with the distribution.
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
|
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
import os
|
|
|
|
from ansible.module_utils.six import iteritems
|
|
|
|
|
|
def openstack_argument_spec():
|
|
# DEPRECATED: This argument spec is only used for the deprecated old
|
|
# OpenStack modules. It turns out that modern OpenStack auth is WAY
|
|
# more complex than this.
|
|
# Consume standard OpenStack environment variables.
|
|
# This is mainly only useful for ad-hoc command line operation as
|
|
# in playbooks one would assume variables would be used appropriately
|
|
OS_AUTH_URL = os.environ.get('OS_AUTH_URL', 'http://127.0.0.1:35357/v2.0/')
|
|
OS_PASSWORD = os.environ.get('OS_PASSWORD', None)
|
|
OS_REGION_NAME = os.environ.get('OS_REGION_NAME', None)
|
|
OS_USERNAME = os.environ.get('OS_USERNAME', 'admin')
|
|
OS_TENANT_NAME = os.environ.get('OS_TENANT_NAME', OS_USERNAME)
|
|
|
|
spec = dict(
|
|
login_username=dict(default=OS_USERNAME),
|
|
auth_url=dict(default=OS_AUTH_URL),
|
|
region_name=dict(default=OS_REGION_NAME),
|
|
availability_zone=dict(),
|
|
)
|
|
if OS_PASSWORD:
|
|
spec['login_password'] = dict(default=OS_PASSWORD)
|
|
else:
|
|
spec['login_password'] = dict(required=True)
|
|
if OS_TENANT_NAME:
|
|
spec['login_tenant_name'] = dict(default=OS_TENANT_NAME)
|
|
else:
|
|
spec['login_tenant_name'] = dict(required=True)
|
|
return spec
|
|
|
|
|
|
def openstack_find_nova_addresses(addresses, ext_tag, key_name=None):
|
|
|
|
ret = []
|
|
for (k, v) in iteritems(addresses):
|
|
if key_name and k == key_name:
|
|
ret.extend([addrs['addr'] for addrs in v])
|
|
else:
|
|
for interface_spec in v:
|
|
if 'OS-EXT-IPS:type' in interface_spec and interface_spec['OS-EXT-IPS:type'] == ext_tag:
|
|
ret.append(interface_spec['addr'])
|
|
return ret
|
|
|
|
|
|
def openstack_full_argument_spec(**kwargs):
|
|
spec = dict(
|
|
cloud=dict(default=None, type='raw'),
|
|
auth_type=dict(default=None),
|
|
auth=dict(default=None, type='dict', no_log=True),
|
|
region_name=dict(default=None),
|
|
availability_zone=dict(default=None),
|
|
validate_certs=dict(default=None, type='bool', aliases=['verify']),
|
|
ca_cert=dict(default=None, aliases=['cacert']),
|
|
client_cert=dict(default=None, aliases=['cert']),
|
|
client_key=dict(default=None, no_log=True, aliases=['key']),
|
|
wait=dict(default=True, type='bool'),
|
|
timeout=dict(default=180, type='int'),
|
|
api_timeout=dict(default=None, type='int'),
|
|
interface=dict(
|
|
default='public', choices=['public', 'internal', 'admin'],
|
|
aliases=['endpoint_type']),
|
|
)
|
|
spec.update(kwargs)
|
|
return spec
|
|
|
|
|
|
def openstack_module_kwargs(**kwargs):
|
|
ret = {}
|
|
for key in ('mutually_exclusive', 'required_together', 'required_one_of'):
|
|
if key in kwargs:
|
|
if key in ret:
|
|
ret[key].extend(kwargs[key])
|
|
else:
|
|
ret[key] = kwargs[key]
|
|
|
|
return ret
|
|
|
|
|
|
def openstack_cloud_from_module(module, min_version='0.12.0'):
|
|
from distutils.version import StrictVersion
|
|
try:
|
|
# Due to the name shadowing we should import other way
|
|
import importlib
|
|
sdk = importlib.import_module('openstack')
|
|
except ImportError:
|
|
module.fail_json(msg='openstacksdk is required for this module')
|
|
|
|
if min_version:
|
|
if StrictVersion(sdk.version.__version__) < StrictVersion(min_version):
|
|
module.fail_json(
|
|
msg="To utilize this module, the installed version of"
|
|
"the openstacksdk library MUST be >={min_version}".format(
|
|
min_version=min_version))
|
|
|
|
cloud_config = module.params.pop('cloud', None)
|
|
try:
|
|
if isinstance(cloud_config, dict):
|
|
fail_message = (
|
|
"A cloud config dict was provided to the cloud parameter"
|
|
" but also a value was provided for {param}. If a cloud"
|
|
" config dict is provided, {param} should be"
|
|
" excluded.")
|
|
for param in (
|
|
'auth', 'region_name', 'validate_certs',
|
|
'ca_cert', 'client_key', 'api_timeout', 'auth_type'):
|
|
if module.params[param] is not None:
|
|
module.fail_json(msg=fail_message.format(param=param))
|
|
# For 'interface' parameter, fail if we receive a non-default value
|
|
if module.params['interface'] != 'public':
|
|
module.fail_json(msg=fail_message.format(param='interface'))
|
|
return sdk, sdk.connect(**cloud_config)
|
|
else:
|
|
return sdk, sdk.connect(
|
|
cloud=cloud_config,
|
|
auth_type=module.params['auth_type'],
|
|
auth=module.params['auth'],
|
|
region_name=module.params['region_name'],
|
|
verify=module.params['validate_certs'],
|
|
cacert=module.params['ca_cert'],
|
|
key=module.params['client_key'],
|
|
api_timeout=module.params['api_timeout'],
|
|
interface=module.params['interface'],
|
|
)
|
|
except sdk.exceptions.SDKException as e:
|
|
# Probably a cloud configuration/login error
|
|
module.fail_json(msg=str(e))
|