mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-16 11:58:43 +00:00
(cherry picked from commit4e6ac335f3) (cherry picked from commit40bef226c0) Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
8d19ad9f86
commit
14ec6c5d11
2
changelogs/fragments/554-env-vars.yml
Normal file
2
changelogs/fragments/554-env-vars.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- "most modules - fix handling of ``DOCKER_TIMEOUT`` environment variable, and improve handling of other fallback environment variables (https://github.com/ansible-collections/community.docker/issues/551, https://github.com/ansible-collections/community.docker/pull/554)."
|
||||||
@ -338,13 +338,17 @@ class AnsibleDockerClientBase(Client):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_value(param_name, param_value, env_variable, default_value):
|
def _get_value(param_name, param_value, env_variable, default_value, type='str'):
|
||||||
if param_value is not None:
|
if param_value is not None:
|
||||||
# take module parameter value
|
# take module parameter value
|
||||||
|
if type == 'bool':
|
||||||
if param_value in BOOLEANS_TRUE:
|
if param_value in BOOLEANS_TRUE:
|
||||||
return True
|
return True
|
||||||
if param_value in BOOLEANS_FALSE:
|
if param_value in BOOLEANS_FALSE:
|
||||||
return False
|
return False
|
||||||
|
return bool(param_value)
|
||||||
|
if type == 'int':
|
||||||
|
return int(param_value)
|
||||||
return param_value
|
return param_value
|
||||||
|
|
||||||
if env_variable is not None:
|
if env_variable is not None:
|
||||||
@ -357,10 +361,14 @@ class AnsibleDockerClientBase(Client):
|
|||||||
return os.path.join(env_value, 'ca.pem')
|
return os.path.join(env_value, 'ca.pem')
|
||||||
if param_name == 'key_path':
|
if param_name == 'key_path':
|
||||||
return os.path.join(env_value, 'key.pem')
|
return os.path.join(env_value, 'key.pem')
|
||||||
|
if type == 'bool':
|
||||||
if env_value in BOOLEANS_TRUE:
|
if env_value in BOOLEANS_TRUE:
|
||||||
return True
|
return True
|
||||||
if env_value in BOOLEANS_FALSE:
|
if env_value in BOOLEANS_FALSE:
|
||||||
return False
|
return False
|
||||||
|
return bool(env_value)
|
||||||
|
if type == 'int':
|
||||||
|
return int(env_value)
|
||||||
return env_value
|
return env_value
|
||||||
|
|
||||||
# take the default
|
# take the default
|
||||||
@ -385,21 +393,21 @@ class AnsibleDockerClientBase(Client):
|
|||||||
|
|
||||||
result = dict(
|
result = dict(
|
||||||
docker_host=self._get_value('docker_host', params['docker_host'], 'DOCKER_HOST',
|
docker_host=self._get_value('docker_host', params['docker_host'], 'DOCKER_HOST',
|
||||||
DEFAULT_DOCKER_HOST),
|
DEFAULT_DOCKER_HOST, type='str'),
|
||||||
tls_hostname=self._get_value('tls_hostname', params['tls_hostname'],
|
tls_hostname=self._get_value('tls_hostname', params['tls_hostname'],
|
||||||
'DOCKER_TLS_HOSTNAME', None),
|
'DOCKER_TLS_HOSTNAME', None, type='str'),
|
||||||
api_version=self._get_value('api_version', params['api_version'], 'DOCKER_API_VERSION',
|
api_version=self._get_value('api_version', params['api_version'], 'DOCKER_API_VERSION',
|
||||||
'auto'),
|
'auto', type='str'),
|
||||||
cacert_path=self._get_value('cacert_path', params['ca_cert'], 'DOCKER_CERT_PATH', None),
|
cacert_path=self._get_value('cacert_path', params['ca_cert'], 'DOCKER_CERT_PATH', None, type='str'),
|
||||||
cert_path=self._get_value('cert_path', params['client_cert'], 'DOCKER_CERT_PATH', None),
|
cert_path=self._get_value('cert_path', params['client_cert'], 'DOCKER_CERT_PATH', None, type='str'),
|
||||||
key_path=self._get_value('key_path', params['client_key'], 'DOCKER_CERT_PATH', None),
|
key_path=self._get_value('key_path', params['client_key'], 'DOCKER_CERT_PATH', None, type='str'),
|
||||||
ssl_version=self._get_value('ssl_version', params['ssl_version'], 'DOCKER_SSL_VERSION', None),
|
ssl_version=self._get_value('ssl_version', params['ssl_version'], 'DOCKER_SSL_VERSION', None, type='str'),
|
||||||
tls=self._get_value('tls', params['tls'], 'DOCKER_TLS', DEFAULT_TLS),
|
tls=self._get_value('tls', params['tls'], 'DOCKER_TLS', DEFAULT_TLS, type='bool'),
|
||||||
tls_verify=self._get_value('tls_verfy', params['validate_certs'], 'DOCKER_TLS_VERIFY',
|
tls_verify=self._get_value('tls_verfy', params['validate_certs'], 'DOCKER_TLS_VERIFY',
|
||||||
DEFAULT_TLS_VERIFY),
|
DEFAULT_TLS_VERIFY, type='bool'),
|
||||||
timeout=self._get_value('timeout', params['timeout'], 'DOCKER_TIMEOUT',
|
timeout=self._get_value('timeout', params['timeout'], 'DOCKER_TIMEOUT',
|
||||||
DEFAULT_TIMEOUT_SECONDS),
|
DEFAULT_TIMEOUT_SECONDS, type='int'),
|
||||||
use_ssh_client=self._get_value('use_ssh_client', params['use_ssh_client'], None, False),
|
use_ssh_client=self._get_value('use_ssh_client', params['use_ssh_client'], None, False, type='bool'),
|
||||||
)
|
)
|
||||||
|
|
||||||
def depr(*args, **kwargs):
|
def depr(*args, **kwargs):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user