From e715f7f9688d797eabac1991a8934ab74ca64a42 Mon Sep 17 00:00:00 2001 From: Constantin Bugneac Date: Fri, 16 Oct 2015 16:08:10 +0100 Subject: [PATCH 1/9] Included 'block_device_mapping' in the output of module and other missing attributes --- cloud/amazon/ec2_ami_find.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cloud/amazon/ec2_ami_find.py b/cloud/amazon/ec2_ami_find.py index f5ed91baab5..3940bf0fc01 100644 --- a/cloud/amazon/ec2_ami_find.py +++ b/cloud/amazon/ec2_ami_find.py @@ -165,12 +165,32 @@ EXAMPLES = ''' try: import boto.ec2 + from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping HAS_BOTO=True except ImportError: HAS_BOTO=False import json +def get_block_device_mapping(image): + """ + Retrieves block device mapping from AMI + """ + + bdm_dict = dict() + bdm = getattr(image,'block_device_mapping') + for device_name in bdm.keys(): + bdm_dict[device_name] = { + 'size': bdm[device_name].size, + 'snapshot_id': bdm[device_name].snapshot_id, + 'volume_type': bdm[device_name].volume_type, + 'encrypted': bdm[device_name].encrypted, + 'delete_on_termination': bdm[device_name].delete_on_termination + } + + return bdm_dict + + def main(): argument_spec = ec2_argument_spec() argument_spec.update(dict( @@ -255,8 +275,12 @@ def main(): data = { 'ami_id': image.id, 'architecture': image.architecture, + 'block_device_mapping': get_block_device_mapping(image), + 'creationDate': image.creationDate, 'description': image.description, + 'hypervisor': image.hypervisor, 'is_public': image.is_public, + 'location': image.location, 'name': image.name, 'owner_id': image.owner_id, 'platform': image.platform, From 01b84324965c1122df3375561de093aa8ae5fd1b Mon Sep 17 00:00:00 2001 From: Constantin Bugneac Date: Tue, 20 Oct 2015 09:30:57 +0100 Subject: [PATCH 2/9] Added documentation for returned structure --- cloud/amazon/ec2_ami_find.py | 100 ++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/cloud/amazon/ec2_ami_find.py b/cloud/amazon/ec2_ami_find.py index 3940bf0fc01..c060f0fb9ee 100644 --- a/cloud/amazon/ec2_ami_find.py +++ b/cloud/amazon/ec2_ami_find.py @@ -163,6 +163,105 @@ EXAMPLES = ''' wait: yes ''' +RETURN = ''' +ami_id: + description: id of found amazon image + returned: when AMI found + type: string + sample: "ami-e9095e8c" +architecture: + description: architecture of image + returned: when AMI found + type: string + sample: "x86_64" +architecture: + description: architecture of image + returned: when AMI found + type: string + sample: "x86_64" +block_device_mapping: + description: block device mapping associated with image + returned: when AMI found + type: dictionary of block devices + sample: { + "/dev/xvda": { + "delete_on_termination": true, + "encrypted": false, + "size": 8, + "snapshot_id": "snap-ca0330b8", + "volume_type": "gp2" + } +creationDate: + description: creation date of image + returned: when AMI found + type: string + sample: "2015-10-15T22:43:44.000Z" +description: + description: description of image + returned: when AMI found + type: string + sample: "test-server01" +hypervisor: + description: type of hypervisor + returned: when AMI found + type: string + sample: "xen" +is_public: + description: whether image is public + returned: when AMI found + type: bool + sample: false +location: + description: location of image + returned: when AMI found + type: string + sample: "435210894375/test-server01-20151015-234343" +name: + description: ami name of image + returned: when AMI found + type: string + sample: "test-server01-20151015-234343" +owner_id: + description: owner of image + returned: when AMI found + type: string + sample: "435210894375" +platform: + description: plaform of image + returned: when AMI found + type: string + sample: null +root_device_name: + description: rood device name of image + returned: when AMI found + type: string + sample: "/dev/xvda" +root_device_type: + description: rood device type of image + returned: when AMI found + type: string + sample: "ebs" +state: + description: state of image + returned: when AMI found + type: string + sample: "available" +tags: + description: tags assigned to image + returned: when AMI found + type: dictionary of tags + sample: { + "Environment": "devel", + "Name": "test-server01", + "Role": "web" + } +virtualization_type: + description: image virtualization type + returned: when AMI found + type: string + sample: "hvm" +''' + try: import boto.ec2 from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping @@ -323,4 +422,3 @@ from ansible.module_utils.ec2 import * if __name__ == '__main__': main() - From cdf7117f7eec002ff6fce5900d2706e8a1abc399 Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Tue, 20 Oct 2015 13:29:41 -0400 Subject: [PATCH 3/9] Add OpenStack Keystone User module This is a replacement for PR #1598 and fixes #283 --- .../{keystone_user.py => _keystone_user.py} | 1 + cloud/openstack/os_user.py | 178 ++++++++++++++++++ 2 files changed, 179 insertions(+) rename cloud/openstack/{keystone_user.py => _keystone_user.py} (99%) create mode 100644 cloud/openstack/os_user.py diff --git a/cloud/openstack/keystone_user.py b/cloud/openstack/_keystone_user.py similarity index 99% rename from cloud/openstack/keystone_user.py rename to cloud/openstack/_keystone_user.py index babcc3cc569..48cc87b241a 100644 --- a/cloud/openstack/keystone_user.py +++ b/cloud/openstack/_keystone_user.py @@ -21,6 +21,7 @@ DOCUMENTATION = ''' --- module: keystone_user version_added: "1.2" +deprecated: Deprecated in 2.0. Use os_user instead short_description: Manage OpenStack Identity (keystone) users, tenants and roles description: - Manage users,tenants, roles from OpenStack. diff --git a/cloud/openstack/os_user.py b/cloud/openstack/os_user.py new file mode 100644 index 00000000000..79c315c959d --- /dev/null +++ b/cloud/openstack/os_user.py @@ -0,0 +1,178 @@ +#!/usr/bin/python +# Copyright (c) 2015 Hewlett-Packard Development Company, L.P. +# +# This module is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software. If not, see . + + +try: + import shade + HAS_SHADE = True +except ImportError: + HAS_SHADE = False + +DOCUMENTATION = ''' +--- +module: os_user +short_description: Manage OpenStack Identity Users +extends_documentation_fragment: openstack +version_added: "2.0" +description: + - Manage OpenStack Identity users. Users can be created, + updated or deleted using this module. A user will be updated + if I(name) matches an existing user and I(state) is present. + The value for I(name) cannot be updated without deleting and + re-creating the user. +options: + name: + description: + - Username for the user + required: true + password: + description: + - Password for the user + required: true + email: + description: + - Email address for the user + required: false + default: None + default_project: + description: + - Project name or ID that the user should be associated with by default + required: false + default: None + domain: + description: + - Domain to create the user in if the cloud supports domains + required: false + default: None + enabled: + description: + - Is the user enabled + required: false + default: True + state: + description: + - Should the resource be present or absent. + choices: [present, absent] + default: present +requirements: + - "python >= 2.6" + - "shade" +''' + +EXAMPLES = ''' +# Create a user +- os_user: + cloud: mycloud + state: present + name: demouser + password: secret + email: demo@example.com + domain: default + default_project: demo + +# Delete a user +- os_user: + cloud: mycloud + state: absent + name: demouser +''' + + +def _needs_update(module, user): + keys = ('email', 'default_project', 'domain', 'enabled') + for key in keys: + if module.params[key] is not None and module.params[key] != user.get(key): + return True + + # We don't get password back in the user object, so assume any supplied + # password is a change. + if module.params['password'] is not None: + return True + + return False + +def main(): + + argument_spec = openstack_full_argument_spec( + name=dict(required=True), + password=dict(required=False, default=None), + email=dict(required=False, default=None), + default_project=dict(required=False, default=None), + domain=dict(required=False, default=None), + enabled=dict(default=True, type='bool'), + state=dict(default='present', choices=['absent', 'present']), + ) + + module_kwargs = openstack_module_kwargs() + module = AnsibleModule(argument_spec, **module_kwargs) + + if not HAS_SHADE: + module.fail_json(msg='shade is required for this module') + + name = module.params['name'] + password = module.params['password'] + email = module.params['email'] + default_project = module.params['default_project'] + domain = module.params['domain'] + enabled = module.params['enabled'] + state = module.params['state'] + + try: + cloud = shade.openstack_cloud(**module.params) + user = cloud.get_user(name) + + project_id = None + if default_project: + project = cloud.get_project(default_project) + if not project: + module.fail_json(msg='Default project %s is not valid' % default_project) + project_id = project['id'] + + if state == 'present': + if user is None: + user = cloud.create_user( + name=name, password=password, email=email, + default_project=default_project, domain_id=domain, + enabled=enabled) + changed = True + else: + if _needs_update(module, user): + user = cloud.update_user( + user['id'], password=password, email=email, + default_project=project_id, domain_id=domain, + enabled=enabled) + changed = True + else: + changed = False + module.exit_json(changed=changed, user=user) + + elif state == 'absent': + if user is None: + changed=False + else: + cloud.delete_user(user['id']) + changed=True + module.exit_json(changed=changed) + + except shade.OpenStackCloudException as e: + module.fail_json(msg=e.message, extra_data=e.extra_data) + +from ansible.module_utils.basic import * +from ansible.module_utils.openstack import * + + +if __name__ == '__main__': + main() From fde149cbe853919f9727882bdfa6d5b47b018b4b Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Tue, 20 Oct 2015 15:14:22 -0400 Subject: [PATCH 4/9] Clarify password requirement and add return docs. --- cloud/openstack/os_user.py | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/cloud/openstack/os_user.py b/cloud/openstack/os_user.py index 79c315c959d..f5baa6fc75a 100644 --- a/cloud/openstack/os_user.py +++ b/cloud/openstack/os_user.py @@ -41,7 +41,8 @@ options: password: description: - Password for the user - required: true + required: true when I(state) is present + default: None email: description: - Email address for the user @@ -91,6 +92,34 @@ EXAMPLES = ''' ''' +RETURN = ''' +user: + description: Dictionary describing the user. + returned: On success when I(state) is 'present' + type: dictionary + contains: + default_project_id: + description: User default project ID. Only present with Keystone >= v3. + type: string + sample: "4427115787be45f08f0ec22a03bfc735" + domain_id: + description: User domain ID. Only present with Keystone >= v3. + type: string + sample: "default" + email: + description: User email address + type: string + sample: "demo@example.com" + id: + description: User ID + type: string + sample: "f59382db809c43139982ca4189404650" + name: + description: User name + type: string + sample: "demouser" +''' + def _needs_update(module, user): keys = ('email', 'default_project', 'domain', 'enabled') for key in keys: @@ -117,7 +146,12 @@ def main(): ) module_kwargs = openstack_module_kwargs() - module = AnsibleModule(argument_spec, **module_kwargs) + module = AnsibleModule( + argument_spec, + required_if=[ + ('state', 'present', ['password']) + ], + **module_kwargs) if not HAS_SHADE: module.fail_json(msg='shade is required for this module') From dc51e1ae41c4a4898555866784fc543147f25368 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Tue, 20 Oct 2015 15:34:50 -0700 Subject: [PATCH 5/9] Mark a few parameters as no_log --- system/user.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/system/user.py b/system/user.py index c2e4956f897..c04b748f068 100755 --- a/system/user.py +++ b/system/user.py @@ -2045,7 +2045,7 @@ def main(): comment=dict(default=None, type='str'), home=dict(default=None, type='str'), shell=dict(default=None, type='str'), - password=dict(default=None, type='str'), + password=dict(default=None, type='str', no_log=True), login_class=dict(default=None, type='str'), # following options are specific to userdel force=dict(default='no', type='bool'), @@ -2063,7 +2063,7 @@ def main(): ssh_key_type=dict(default=ssh_defaults['type'], type='str'), ssh_key_file=dict(default=None, type='str'), ssh_key_comment=dict(default=ssh_defaults['comment'], type='str'), - ssh_key_passphrase=dict(default=None, type='str'), + ssh_key_passphrase=dict(default=None, type='str', no_log=True), update_password=dict(default='always',choices=['always','on_create'],type='str'), expires=dict(default=None, type='float'), ), @@ -2161,4 +2161,5 @@ def main(): # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() From 2b33c92e7ab24612d2d10c0c68fa08fc806733b0 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 21 Oct 2015 09:24:12 -0400 Subject: [PATCH 6/9] corrected docs for stat's lnk_source fixes #12850 --- files/stat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/stat.py b/files/stat.py index 2e088fc8dbd..8f2bd289bc0 100644 --- a/files/stat.py +++ b/files/stat.py @@ -245,8 +245,8 @@ stat: lnk_source: description: Original path returned: success, path exists and user can read stats and the path is a symbolic link - type: boolean - sample: True + type: string + sample: /home/foobar/21102015-1445431274-908472971 md5: description: md5 hash of the path returned: success, path exists and user can read stats and path supports hashing and md5 is supported From e41cde3116684fe42ff0cd5b789a0313c44fe233 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 21 Oct 2015 08:36:08 -0700 Subject: [PATCH 7/9] Correct docs build --- cloud/amazon/ec2_ami_find.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cloud/amazon/ec2_ami_find.py b/cloud/amazon/ec2_ami_find.py index c060f0fb9ee..a1cb4fec396 100644 --- a/cloud/amazon/ec2_ami_find.py +++ b/cloud/amazon/ec2_ami_find.py @@ -184,8 +184,8 @@ block_device_mapping: returned: when AMI found type: dictionary of block devices sample: { - "/dev/xvda": { - "delete_on_termination": true, + "/dev/xvda": { + "delete_on_termination": true, "encrypted": false, "size": 8, "snapshot_id": "snap-ca0330b8", @@ -251,8 +251,8 @@ tags: returned: when AMI found type: dictionary of tags sample: { - "Environment": "devel", - "Name": "test-server01", + "Environment": "devel", + "Name": "test-server01", "Role": "web" } virtualization_type: From bc3b1abd68d516799e8f92e72187ab4cf58e7e0a Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 21 Oct 2015 08:40:10 -0700 Subject: [PATCH 8/9] Another fix for docs --- cloud/amazon/ec2_ami_find.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cloud/amazon/ec2_ami_find.py b/cloud/amazon/ec2_ami_find.py index a1cb4fec396..ce7506e0961 100644 --- a/cloud/amazon/ec2_ami_find.py +++ b/cloud/amazon/ec2_ami_find.py @@ -183,14 +183,14 @@ block_device_mapping: description: block device mapping associated with image returned: when AMI found type: dictionary of block devices - sample: { - "/dev/xvda": { - "delete_on_termination": true, - "encrypted": false, - "size": 8, - "snapshot_id": "snap-ca0330b8", - "volume_type": "gp2" - } + sample: "{ + '/dev/xvda': { + 'delete_on_termination': true, + 'encrypted': false, + 'size': 8, + 'snapshot_id': 'snap-ca0330b8', + 'volume_type': 'gp2' + }" creationDate: description: creation date of image returned: when AMI found @@ -250,11 +250,11 @@ tags: description: tags assigned to image returned: when AMI found type: dictionary of tags - sample: { - "Environment": "devel", - "Name": "test-server01", - "Role": "web" - } + sample: "{ + 'Environment': 'devel', + 'Name': 'test-server01', + 'Role': 'web' + }" virtualization_type: description: image virtualization type returned: when AMI found From 83b52200682619b291b54781c9643954bce4f3d1 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 21 Oct 2015 13:57:47 -0400 Subject: [PATCH 9/9] clarified ping module purpose --- system/ping.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/system/ping.py b/system/ping.py index bea7fb22f1d..1449cf5dca9 100644 --- a/system/ping.py +++ b/system/ping.py @@ -23,19 +23,20 @@ DOCUMENTATION = ''' --- module: ping version_added: historical -short_description: Try to connect to host and return C(pong) on success. +short_description: Try to connect to host, veryify a usable python and return C(pong) on success. description: - A trivial test module, this module always returns C(pong) on successful contact. It does not make sense in playbooks, but it is useful from - C(/usr/bin/ansible) + C(/usr/bin/ansible) to verify the ability to login and that a usable python is configured. + - This is NOT ICMP ping, this is just a trivial test module. options: {} -author: +author: - "Ansible Core Team" - "Michael DeHaan" ''' EXAMPLES = ''' -# Test 'webservers' status +# Test we can logon to 'webservers' and execute python with json lib. ansible webservers -m ping '''