def associate_profile_to_role(profile_name, role_name, region=None, key=None, keyid=None, profile=None):
 conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
 if (not role_exists(role_name, region, key, keyid, profile)):
  log.error('IAM role {0} does not exist.'.format(role_name))
  return False
 if (not instance_profile_exists(profile_name, region, key, keyid, profile)):
  log.error('Instance profile {0} does not exist.'.format(profile_name))
  return False
 associated = profile_associated(role_name, profile_name, region, key, keyid, profile)
 if associated:
  return True
 else:
  try:
   conn.add_role_to_instance_profile(profile_name, role_name)
   msg = 'Added {0} instance profile to {1} role.'
   log.info(msg.format(profile_name, role_name))
   return True
  except boto.exception.BotoServerError as e:
   log.debug(e)
   msg = 'Failed to add {0} instance profile to {1} role.'
   log.error(msg.format(profile_name, role_name))
   return False

def associate_profile_to_role ( profile_name , role_name , region = None , key = None , keyid = None , profile = None ) : conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) if ( not role_exists ( role_name , region , key , keyid , profile ) ) : log . error ( 'IAM role {0} does not exist.' . format ( role_name ) ) return False if ( not instance_profile_exists ( profile_name , region , key , keyid , profile ) ) : log . error ( 'Instance profile {0} does not exist.' . format ( profile_name ) ) return False associated = profile_associated ( role_name , profile_name , region , key , keyid , profile ) if associated : return True else : try : conn . add_role_to_instance_profile ( profile_name , role_name ) msg = 'Added {0} instance profile to {1} role.' log . info ( msg . format ( profile_name , role_name ) ) return True except boto . exception . BotoServerError as e : log . debug ( e ) msg = 'Failed to add {0} instance profile to {1} role.' log . error ( msg . format ( profile_name , role_name ) ) return False
associate an instance profile with an iam role .