From 0ca50c7d6fb63cafd6af57fe969bc7d62c8d1023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Tue, 11 Jun 2019 07:49:24 +0200 Subject: [PATCH] vultr: vultr_user_facts -> info (#57564) * vultr: deprecate vultr_user_facts * vultr: vultr_user_facts: rename to info * vultr: adjust tests * vultr: new vultr_user_info module --- ...ltr_user_facts.py => _vultr_user_facts.py} | 6 +- .../modules/cloud/vultr/vultr_user_info.py | 140 ++++++++++++++++++ .../targets/vultr_user_facts/tasks/main.yml | 31 ---- .../aliases | 0 .../defaults/main.yml | 4 +- .../targets/vultr_user_info/tasks/main.yml | 34 +++++ 6 files changed, 181 insertions(+), 34 deletions(-) rename lib/ansible/modules/cloud/vultr/{vultr_user_facts.py => _vultr_user_facts.py} (94%) create mode 100644 lib/ansible/modules/cloud/vultr/vultr_user_info.py delete mode 100644 test/integration/targets/vultr_user_facts/tasks/main.yml rename test/integration/targets/{vultr_user_facts => vultr_user_info}/aliases (100%) rename test/integration/targets/{vultr_user_facts => vultr_user_info}/defaults/main.yml (57%) create mode 100644 test/integration/targets/vultr_user_info/tasks/main.yml diff --git a/lib/ansible/modules/cloud/vultr/vultr_user_facts.py b/lib/ansible/modules/cloud/vultr/_vultr_user_facts.py similarity index 94% rename from lib/ansible/modules/cloud/vultr/vultr_user_facts.py rename to lib/ansible/modules/cloud/vultr/_vultr_user_facts.py index ae4324137fc..b27ab4bbbcf 100644 --- a/lib/ansible/modules/cloud/vultr/vultr_user_facts.py +++ b/lib/ansible/modules/cloud/vultr/_vultr_user_facts.py @@ -7,7 +7,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], + 'status': ['deprecated'], 'supported_by': 'community'} DOCUMENTATION = r''' @@ -18,6 +18,10 @@ description: - Gather facts about users available in Vultr. version_added: "2.7" author: "Yanis Guenane (@Spredzy)" +deprecated: + removed_in: "2.12" + why: Transformed into an info module. + alternative: Use M(vultr_user_info) instead. extends_documentation_fragment: vultr ''' diff --git a/lib/ansible/modules/cloud/vultr/vultr_user_info.py b/lib/ansible/modules/cloud/vultr/vultr_user_info.py new file mode 100644 index 00000000000..6675febc15e --- /dev/null +++ b/lib/ansible/modules/cloud/vultr/vultr_user_info.py @@ -0,0 +1,140 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Copyright (c) 2018, Yanis Guenane +# Copyright (c) 2019, René Moser +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community'} + +DOCUMENTATION = r''' +--- +module: vultr_user_info +short_description: Get infos about the Vultr user available. +description: + - Get infos about users available in Vultr. +version_added: "2.9" +author: + - "Yanis Guenane (@Spredzy)" + - "René Moser (@resmo)" +extends_documentation_fragment: vultr +''' + +EXAMPLES = r''' +- name: Get Vultr user infos + vultr_user_info: + register: result + +- name: Print the infos + debug: + var: result.vultr_user_info +''' + +RETURN = r''' +--- +vultr_api: + description: Response from Vultr API with a few additions/modification + returned: success + type: complex + contains: + api_account: + description: Account used in the ini file to select the key + returned: success + type: str + sample: default + api_timeout: + description: Timeout used for the API requests + returned: success + type: int + sample: 60 + api_retries: + description: Amount of max retries for the API requests + returned: success + type: int + sample: 5 + api_endpoint: + description: Endpoint used for the API requests + returned: success + type: str + sample: "https://api.vultr.com" +vultr_user_info: + description: Response from Vultr API as list + returned: available + type: complex + contains: + id: + description: ID of the user. + returned: success + type: str + sample: 5904bc6ed9234 + api_key: + description: API key of the user. + returned: only after resource was created + type: str + sample: 567E6K567E6K567E6K567E6K567E6K + name: + description: Name of the user. + returned: success + type: str + sample: john + email: + description: Email of the user. + returned: success + type: str + sample: "john@exmaple.com" + api_enabled: + description: Whether the API is enabled or not. + returned: success + type: bool + sample: true + acls: + description: List of ACLs of the user. + returned: success + type: list + sample: [ manage_users, support, upgrade ] +''' + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.vultr import ( + Vultr, + vultr_argument_spec, +) + + +class AnsibleVultrUserInfo(Vultr): + + def __init__(self, module): + super(AnsibleVultrUserInfo, self).__init__(module, "vultr_user_info") + + self.returns = { + "USERID": dict(key='id'), + "acls": dict(), + "api_enabled": dict(), + "email": dict(), + "name": dict() + } + + def get_regions(self): + return self.api_query(path="/v1/user/list") + + +def main(): + argument_spec = vultr_argument_spec() + + module = AnsibleModule( + argument_spec=argument_spec, + supports_check_mode=True, + ) + + user_info = AnsibleVultrUserInfo(module) + result = user_info.get_result(user_info.get_regions()) + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/vultr_user_facts/tasks/main.yml b/test/integration/targets/vultr_user_facts/tasks/main.yml deleted file mode 100644 index f70622214a3..00000000000 --- a/test/integration/targets/vultr_user_facts/tasks/main.yml +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (c) 2018, Yanis Guenane -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) ---- -- name: Create the user - vultr_user: - name: '{{ user_name }}' - email: '{{ user_email }}' - password: '{{ user_password }}' - acls: '{{ user_acls }}' - -- name: test gather vultr user facts in check mode - vultr_user_facts: - check_mode: yes - -- name: verify test gather vultr user facts in check mode - assert: - that: - - ansible_facts.vultr_user_facts|selectattr('name','equalto','{{ user_name }}') | list | count == 1 - -- name: test gather vultr user facts - vultr_user_facts: - -- name: verify test gather vultr user facts - assert: - that: - - ansible_facts.vultr_user_facts|selectattr('name','equalto','{{ user_name }}') | list | count == 1 - -- name: Delete the user - vultr_user: - name: '{{ user_name }}' - state: absent diff --git a/test/integration/targets/vultr_user_facts/aliases b/test/integration/targets/vultr_user_info/aliases similarity index 100% rename from test/integration/targets/vultr_user_facts/aliases rename to test/integration/targets/vultr_user_info/aliases diff --git a/test/integration/targets/vultr_user_facts/defaults/main.yml b/test/integration/targets/vultr_user_info/defaults/main.yml similarity index 57% rename from test/integration/targets/vultr_user_facts/defaults/main.yml rename to test/integration/targets/vultr_user_info/defaults/main.yml index 6901081331d..5922f6fe24e 100644 --- a/test/integration/targets/vultr_user_facts/defaults/main.yml +++ b/test/integration/targets/vultr_user_info/defaults/main.yml @@ -1,8 +1,8 @@ --- vultr_resource_prefix: "vultr-test-prefix" user_name: "{{ vultr_resource_prefix }}_user" -user_email: mytestuser@example.com -user_password: aP4ssw0rd! +user_email: mytestuser-{{ vultr_resource_prefix }}@example.com +user_password: "{{ vultr_resource_prefix }}aP4ssw0rd!" user_acls: - upgrade - dns diff --git a/test/integration/targets/vultr_user_info/tasks/main.yml b/test/integration/targets/vultr_user_info/tasks/main.yml new file mode 100644 index 00000000000..164c22fc5a7 --- /dev/null +++ b/test/integration/targets/vultr_user_info/tasks/main.yml @@ -0,0 +1,34 @@ +# Copyright (c) 2018, Yanis Guenane +# Copyright (c) 2019, René Moser +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +--- +- name: Create the user + vultr_user: + name: '{{ user_name }}' + email: '{{ user_email }}' + password: '{{ user_password }}' + acls: '{{ user_acls }}' + +- name: test get vultr user info in check mode + vultr_user_info: + register: result + check_mode: yes + +- name: verify test get vultr user info in check mode + assert: + that: + - result.vultr_user_info|selectattr('name','equalto','{{ user_name }}') | list | count == 1 + +- name: test get vultr user info + vultr_user_info: + register: result + +- name: verify test get vultr user info + assert: + that: + - result.vultr_user_info|selectattr('name','equalto','{{ user_name }}') | list | count == 1 + +- name: Delete the user + vultr_user: + name: '{{ user_name }}' + state: absent