diff options
author | Rafael <rvalle@valletech.eu> | 2018-08-27 16:55:04 +0200 |
---|---|---|
committer | Sam Doran <sdoran@redhat.com> | 2018-08-27 10:55:04 -0400 |
commit | ad993ca7347451864a3f398b01db14c1c78b8102 (patch) | |
tree | 6bdf3b496317407a987bb6a3b885f14f3492c0c8 | |
parent | 23eb4f2093855d3a9615bfaf119c20fee7a561f9 (diff) | |
download | ansible-ad993ca7347451864a3f398b01db14c1c78b8102.tar.gz |
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
-rw-r--r-- | lib/ansible/module_utils/opennebula.py | 18 | ||||
-rw-r--r-- | lib/ansible/utils/module_docs_fragments/opennebula.py | 1 | ||||
-rw-r--r-- | test/integration/targets/one_host/tasks/main.yml | 6 |
3 files changed, 13 insertions, 12 deletions
diff --git a/lib/ansible/module_utils/opennebula.py b/lib/ansible/module_utils/opennebula.py index 208ea6c025..a520e32187 100644 --- a/lib/ansible/module_utils/opennebula.py +++ b/lib/ansible/module_utils/opennebula.py @@ -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") diff --git a/lib/ansible/utils/module_docs_fragments/opennebula.py b/lib/ansible/utils/module_docs_fragments/opennebula.py index 6b6e7c0314..233d036a78 100644 --- a/lib/ansible/utils/module_docs_fragments/opennebula.py +++ b/lib/ansible/utils/module_docs_fragments/opennebula.py @@ -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: diff --git a/test/integration/targets/one_host/tasks/main.yml b/test/integration/targets/one_host/tasks/main.yml index 98efedb52e..9ec7413727 100644 --- a/test/integration/targets/one_host/tasks/main.yml +++ b/test/integration/targets/one_host/tasks/main.yml @@ -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 }}" |