Last active
August 29, 2015 14:15
-
-
Save haad/70c6dbcea80131e27895 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| try: | |
| import boto.ec2 | |
| except ImportError: | |
| print "failed=True msg='boto required for this module'" | |
| sys.exit(1) | |
| def main(): | |
| argument_spec = ec2_argument_spec() | |
| argument_spec.update(dict( | |
| region = dict(required=True), | |
| name = dict(required=True), | |
| ) | |
| ) | |
| module = AnsibleModule( | |
| argument_spec=argument_spec, | |
| ) | |
| name = module.params.get('name') | |
| ec2 = ec2_connect(module) | |
| filter = {} | |
| filter['name'] = name | |
| image = ec2.get_all_images(filters=filter) | |
| if len(image) == 0: | |
| module.fail_json(msg="No AMIs matched the name: %s" % name) | |
| elif len(image) > 1: | |
| module.fail_json(msg="More than one AMI matched the name: %s" % name) | |
| else: | |
| module.exit_json(image_id=image[0].id) | |
| # import module snippets | |
| from ansible.module_utils.basic import * | |
| from ansible.module_utils.ec2 import * | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment