def add_tags(gce, module, instance_name, tags):
 zone = module.params.get('zone')
 if (not instance_name):
  module.fail_json(msg='Must supply instance_name', changed=False)
 if (not tags):
  module.fail_json(msg='Must supply tags', changed=False)
 tags = [x.lower() for x in tags]
 try:
  node = gce.ex_get_node(instance_name, zone=zone)
 except ResourceNotFoundError:
  module.fail_json(msg=('Instance %s not found in zone %s' % (instance_name, zone)), changed=False)
 except GoogleBaseError as e:
  module.fail_json(msg=str(e), changed=False)
 node_tags = node.extra['tags']
 changed = False
 tags_changed = []
 for t in tags:
  if (t not in node_tags):
   changed = True
   node_tags.append(t)
   tags_changed.append(t)
 if (not changed):
  return (False, None)
 try:
  gce.ex_set_node_tags(node, node_tags)
  return (True, tags_changed)
 except (GoogleBaseError, InvalidRequestError) as e:
  module.fail_json(msg=str(e), changed=False)

def add_tags ( gce , module , instance_name , tags ) : zone = module . params . get ( 'zone' ) if ( not instance_name ) : module . fail_json ( msg = 'Must supply instance_name' , changed = False ) if ( not tags ) : module . fail_json ( msg = 'Must supply tags' , changed = False ) tags = [ x . lower ( ) for x in tags ] try : node = gce . ex_get_node ( instance_name , zone = zone ) except ResourceNotFoundError : module . fail_json ( msg = ( 'Instance %s not found in zone %s' % ( instance_name , zone ) ) , changed = False ) except GoogleBaseError as e : module . fail_json ( msg = str ( e ) , changed = False ) node_tags = node . extra [ 'tags' ] changed = False tags_changed = [ ] for t in tags : if ( t not in node_tags ) : changed = True node_tags . append ( t ) tags_changed . append ( t ) if ( not changed ) : return ( False , None ) try : gce . ex_set_node_tags ( node , node_tags ) return ( True , tags_changed ) except ( GoogleBaseError , InvalidRequestError ) as e : module . fail_json ( msg = str ( e ) , changed = False )
add tags to a trail returns {tagged: true} if the trail was tagged and returns {tagged: false} if the trail was not tagged .