Serialize facts when necessary

The environment/node templates assume we're passing in serialized facts (since we deserialize on the way out), so this change serializes the non-basestrings .