Backport/2.6/44568 (#44728)

* fixes parameters via environment variables, issue #44163

(cherry picked from commit 2c84022b20)

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

(cherry picked from commit eaaada25c7)

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

(cherry picked from commit e97d2e7ed1)

* added changelog

* yml fix
pull/44664/merge
Rafael 6 years ago committed by Matt Clay
parent ae62f4be32
commit f7f6d47c7e

@ -0,0 +1,2 @@
bugfixes:
- one_host - fixes settings via environment variables (https://github.com/ansible/ansible/pull/44568)

@ -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")

@ -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:

@ -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 }}"

Loading…
Cancel
Save