mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 19:01:26 -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
112 lines
4.7 KiB
Python
112 lines
4.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), Wayne Witzel III <wayne@riotousliving.com>
|
|
# 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
|
|
import traceback
|
|
|
|
TOWER_CLI_IMP_ERR = None
|
|
try:
|
|
import tower_cli.utils.exceptions as exc
|
|
from tower_cli.utils import parser
|
|
from tower_cli.api import client
|
|
|
|
HAS_TOWER_CLI = True
|
|
except ImportError:
|
|
TOWER_CLI_IMP_ERR = traceback.format_exc()
|
|
HAS_TOWER_CLI = False
|
|
|
|
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
|
|
|
|
|
def tower_auth_config(module):
|
|
'''tower_auth_config attempts to load the tower-cli.cfg file
|
|
specified from the `tower_config_file` parameter. If found,
|
|
if returns the contents of the file as a dictionary, else
|
|
it will attempt to fetch values from the module params and
|
|
only pass those values that have been set.
|
|
'''
|
|
config_file = module.params.pop('tower_config_file', None)
|
|
if config_file:
|
|
if not os.path.exists(config_file):
|
|
module.fail_json(msg='file not found: %s' % config_file)
|
|
if os.path.isdir(config_file):
|
|
module.fail_json(msg='directory can not be used as config file: %s' % config_file)
|
|
|
|
with open(config_file, 'rb') as f:
|
|
return parser.string_to_dict(f.read())
|
|
else:
|
|
auth_config = {}
|
|
host = module.params.pop('tower_host', None)
|
|
if host:
|
|
auth_config['host'] = host
|
|
username = module.params.pop('tower_username', None)
|
|
if username:
|
|
auth_config['username'] = username
|
|
password = module.params.pop('tower_password', None)
|
|
if password:
|
|
auth_config['password'] = password
|
|
verify_ssl = module.params.pop('validate_certs', None)
|
|
if verify_ssl is not None:
|
|
auth_config['verify_ssl'] = verify_ssl
|
|
return auth_config
|
|
|
|
|
|
def tower_check_mode(module):
|
|
'''Execute check mode logic for Ansible Tower modules'''
|
|
if module.check_mode:
|
|
try:
|
|
result = client.get('/ping').json()
|
|
module.exit_json(changed=True, tower_version='{0}'.format(result['version']))
|
|
except (exc.ServerError, exc.ConnectionError, exc.BadRequest) as excinfo:
|
|
module.fail_json(changed=False, msg='Failed check mode: {0}'.format(excinfo))
|
|
|
|
|
|
class TowerModule(AnsibleModule):
|
|
def __init__(self, argument_spec, **kwargs):
|
|
args = dict(
|
|
tower_host=dict(),
|
|
tower_username=dict(),
|
|
tower_password=dict(no_log=True),
|
|
validate_certs=dict(type='bool', aliases=['tower_verify_ssl']),
|
|
tower_config_file=dict(type='path'),
|
|
)
|
|
args.update(argument_spec)
|
|
|
|
mutually_exclusive = kwargs.get('mutually_exclusive', [])
|
|
kwargs['mutually_exclusive'] = mutually_exclusive.extend((
|
|
('tower_config_file', 'tower_host'),
|
|
('tower_config_file', 'tower_username'),
|
|
('tower_config_file', 'tower_password'),
|
|
('tower_config_file', 'validate_certs'),
|
|
))
|
|
|
|
super(TowerModule, self).__init__(argument_spec=args, **kwargs)
|
|
|
|
if not HAS_TOWER_CLI:
|
|
self.fail_json(msg=missing_required_lib('ansible-tower-cli'),
|
|
exception=TOWER_CLI_IMP_ERR)
|