1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

one_host environment variables, Fixes #44163 (#44568)

* including test case using environment variables as per issue #44163

* including missing environment variable in shared documentation fragement, related to issue #44163

* fixes parameters via environment variables, issue #44163
This commit is contained in:
Rafael 2018-08-27 16:55:04 +02:00 committed by Sam Doran
parent 23eb4f2093
commit ad993ca734
3 changed files with 13 additions and 12 deletions

View file

@ -28,9 +28,9 @@ class OpenNebulaModule:
"""
common_args = dict(
api_url=dict(type='str', aliases=['api_endpoint']),
api_username=dict(type='str'),
api_password=dict(type='str', no_log=True, aliases=['api_token']),
api_url=dict(type='str', aliases=['api_endpoint'], default=environ.get("ONE_URL")),
api_username=dict(type='str', default=environ.get("ONE_USERNAME")),
api_password=dict(type='str', no_log=True, aliases=['api_token'], default=environ.get("ONE_PASSWORD")),
validate_certs=dict(default=True, type='bool'),
wait_timeout=dict(type='int', default=300),
)
@ -68,18 +68,18 @@ class OpenNebulaModule:
if not HAS_PYONE:
self.fail("pyone is required for this module")
if 'api_url' in self.module.params:
url = self.module.params.get("api_url", environ.get("ONE_URL", False))
if self.module.params.get("api_url"):
url = self.module.params.get("api_url")
else:
self.fail("Either api_url or the environment variable ONE_URL must be provided")
if 'api_username' in self.module.params:
username = self.module.params.get("api_username", environ.get("ONE_USERNAME", False))
if self.module.params.get("api_username"):
username = self.module.params.get("api_username")
else:
self.fail("Either api_username or the environment vairable ONE_USERNAME must be provided")
if 'api_password' in self.module.params:
password = self.module.params.get("api_password", environ.get("ONE_PASSWORD", False))
if self.module.params.get("api_password"):
password = self.module.params.get("api_password")
else:
self.fail("Either api_password or the environment vairable ONE_PASSWORD must be provided")

View file

@ -21,6 +21,7 @@ options:
api_password:
description:
- The password or token for XMLRPC authentication.
If not specified then the value of the ONE_PASSWORD environment variable, if any, is used.
aliases:
- api_token
validate_certs:

View file

@ -72,11 +72,11 @@
one_host:
name: badhost
state: absent
api_url: "{{ opennebula_url }}"
api_username: "{{ opennebula_username }}"
api_password: "{{ opennebula_password }}"
validate_certs: false
environment:
ONE_URL: "{{ opennebula_url }}"
ONE_USERNAME: "{{ opennebula_username }}"
ONE_PASSWORD: "{{ opennebula_password }}"
PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"