Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DigitalOcean: new module: digital_ocean_account_facts #36003

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2018, Ansible Project
# Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com>
# 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 = '''
---
module: digital_ocean_account_facts
short_description: Gather facts about DigitalOcean User account
description:
- This module can be used to gather facts about User account.
author: "Abhijeet Kasurde (@akasurde)"
version_added: "2.6"

requirements:
- "python >= 2.6"

extends_documentation_fragment: digital_ocean.documentation
'''


EXAMPLES = '''
- name: Gather facts about user account
digital_ocean_account_facts:
oauth_token: "{{ oauth_token }}"
'''


RETURN = '''
data:
description: DigitalOcean account facts
returned: success
type: dictionary
sample: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change sample to data that will represent what is being returned to the user.

Example task:

- debug:
    var: resp.data

Outputs:

    "resp.data": {
        "droplet_limit": 100,
        "email": "sammy@digitalocean.com",
        "email_verified": true,
        "floating_ip_limit": 20,
        "status": "active",
        "status_message": "",
        "uuid": "b0ea118ed29548573729203027a0442f9"
    }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sample is actual table header in documentation - e.g., DO Tag return values table.

"droplet_limit": 10,
"email": "testuser1@gmail.com",
"email_verified": true,
"floating_ip_limit": 3,
"status": "active",
"status_message": "",
"uuid": "aaaaaaaaaaaaaa"
}
'''

from traceback import format_exc
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.digital_ocean import DigitalOceanHelper
from ansible.module_utils._text import to_native


def core(module):
rest = DigitalOceanHelper(module)

response = rest.get("account")
if response.status_code != 200:
module.fail_json(msg="Failed to fetch 'account' facts due to error : %s" % response.json['message'])
Copy link
Contributor

@pmarques pmarques Feb 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will not be this caught inside the DO helper?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault, only 401 is handled.


module.exit_json(changed=False, data=response.json["account"])


def main():
argument_spec = DigitalOceanHelper.digital_ocean_argument_spec()
module = AnsibleModule(argument_spec=argument_spec)
try:
core(module)
except Exception as e:
module.fail_json(msg=to_native(e), exception=format_exc())


if __name__ == '__main__':
main()