more idiomatic hostname lookup, ensuring UTF-8 encoding for YAML generation