<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def associate_profile_to_role(profile_name, role_name, region=None, key=None,
                              keyid=None, profile=None):
    '''
    Associate an instance profile with an IAM role.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_iam.associate_profile_to_role myirole myiprofile
    '''
    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 %s does not exist.', role_name)
        return False
    if not instance_profile_exists(profile_name, region, key, keyid, profile):
        log.error('Instance profile %s does not exist.', 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)
            log.info('Added %s instance profile to IAM role %s.', profile_name, role_name)
            return True
        except boto.exception.BotoServerError as e:
            log.debug(e)
            log.error('Failed to add %s instance profile to IAM role %s', profile_name, role_name)
            return False