def upgrade(module, port_path):
    """ Upgrade outdated ports. """

    rc, out, err = module.run_command("%s upgrade outdated" % port_path)

    # rc is 1 when nothing to upgrade so check stdout first.
    if out.strip() == "Nothing to upgrade.":
        changed = False
        msg = "Ports already upgraded"
        return (changed, msg)
    elif rc == 0:
        changed = True
        msg = "Outdated ports upgraded successfully"
        return (changed, msg)
    else:
        module.fail_json(msg="Failed to upgrade outdated ports", stdout=out, stderr=err)