mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Squashed commit of the following:
Changed ami_tags to instance_tags to better follow naming convention Add support for creating tags on the new instances
This commit is contained in:
parent
a894791767
commit
36027ddbba
2 changed files with 21 additions and 3 deletions
|
@ -623,6 +623,9 @@ class AnsibleModule(object):
|
||||||
def jsonify(self, data):
|
def jsonify(self, data):
|
||||||
return json.dumps(data)
|
return json.dumps(data)
|
||||||
|
|
||||||
|
def from_json(self, data):
|
||||||
|
return json.loads(data)
|
||||||
|
|
||||||
def exit_json(self, **kwargs):
|
def exit_json(self, **kwargs):
|
||||||
''' return from the module, without error '''
|
''' return from the module, without error '''
|
||||||
self.add_path_info(kwargs)
|
self.add_path_info(kwargs)
|
||||||
|
|
17
library/ec2
17
library/ec2
|
@ -95,8 +95,15 @@ options:
|
||||||
required: False
|
required: False
|
||||||
default: null
|
default: null
|
||||||
aliases: []
|
aliases: []
|
||||||
|
instance_tags:
|
||||||
|
version_added: "1.0"
|
||||||
|
description:
|
||||||
|
- string of tags, in json format, to add to the new instance
|
||||||
|
required: False
|
||||||
|
default: null
|
||||||
|
aliases: []
|
||||||
examples:
|
examples:
|
||||||
- code: "local_action: ec2 keypair=admin instance_type=m1.large image=emi-40603AD1 wait=true group=webserver count=3"
|
- code: "local_action: ec2 keypair=admin instance_type=m1.large image=emi-40603AD1 wait=true group=webserver count=3 instance_tags='{"Name":"My Server"}'"
|
||||||
description: "Examples from Ansible Playbooks"
|
description: "Examples from Ansible Playbooks"
|
||||||
requirements: [ "boto" ]
|
requirements: [ "boto" ]
|
||||||
author: Seth Vidal, Tim Gerla, Lester Wade
|
author: Seth Vidal, Tim Gerla, Lester Wade
|
||||||
|
@ -126,6 +133,7 @@ def main():
|
||||||
ec2_secret_key = dict(aliases=['EC2_SECRET_KEY']),
|
ec2_secret_key = dict(aliases=['EC2_SECRET_KEY']),
|
||||||
ec2_access_key = dict(aliases=['EC2_ACCESS_KEY']),
|
ec2_access_key = dict(aliases=['EC2_ACCESS_KEY']),
|
||||||
user_data = dict(),
|
user_data = dict(),
|
||||||
|
instance_tags = dict(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -141,6 +149,7 @@ def main():
|
||||||
ec2_secret_key = module.params.get('ec2_secret_key')
|
ec2_secret_key = module.params.get('ec2_secret_key')
|
||||||
ec2_access_key = module.params.get('ec2_access_key')
|
ec2_access_key = module.params.get('ec2_access_key')
|
||||||
user_data = module.params.get('user_data')
|
user_data = module.params.get('user_data')
|
||||||
|
instance_tags = module.params.get('instance_tags')
|
||||||
|
|
||||||
# allow eucarc environment variables to be used if ansible vars aren't set
|
# allow eucarc environment variables to be used if ansible vars aren't set
|
||||||
if not ec2_url and 'EC2_URL' in os.environ:
|
if not ec2_url and 'EC2_URL' in os.environ:
|
||||||
|
@ -170,6 +179,12 @@ def main():
|
||||||
|
|
||||||
instids = [ i.id for i in res.instances ]
|
instids = [ i.id for i in res.instances ]
|
||||||
|
|
||||||
|
if instance_tags:
|
||||||
|
try:
|
||||||
|
ec2.create_tags(instids, module.from_json(instance_tags))
|
||||||
|
except boto.exception.EC2ResponseError as e:
|
||||||
|
module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message))
|
||||||
|
|
||||||
res_list = res.connection.get_all_instances(instids)
|
res_list = res.connection.get_all_instances(instids)
|
||||||
this_res = res_list[0]
|
this_res = res_list[0]
|
||||||
if wait:
|
if wait:
|
||||||
|
|
Loading…
Reference in a new issue