In a large pot of boiling salted water, cook the penne until al dente. Reserve one ladle of cooking water, then drain the pasta and transfer to a serving bowl. In a medium skillet, fry the bacon until crisp and transfer to a plate, leaving the bacon fat in the skillet. Add the onions to the skillet and cook until golden, about 10 minutes. Stir the onions and ricotta into the pasta along with the reserved pasta cooking water. Crumble the bacon and sprinkle it over the pasta along with the basil.