1) NATO took it's action in Libya due to UN Security Council resolution 1973. First several NATO members (and non-members like UAE and Qatar) were attacked to implement the UNSC resolution. A couple weeks later, NATO took over as a coordinating body of the military forces. Some members (like Germany) declined to participate at all.
2) NATO never put Ukraine on the path to membership, although as a result of this invasion they're changing their mind.