I've just been searching for something similar myself and came across the World Countries API, which has a link there to a JSON file; http://www.geognos.com/api/en/countries/info/all.json.
You can also pull out info on a per country basis. Here's Spain; http://www.geognos.com/api/en/countries/info/ES.json
One really nice thing about this API is that it provides plenty more info than the basic country name/code. Here's an example of the output;
"ES": {
"Name": "Spain",
"Capital": {
"DLST": 1,
"TD": 1,
"Flg": 2,
"Name": "Madrid",
"GeoPt": [
40.24,
-3.41
]
},
"GeoRectangle": {
"West": -18.169641,
"East": 4.3153896,
"North": 43.791725,
"South": 27.638817
},
"SeqID": 66,
"GeoPt": [
40,
-4
],
"TelPref": "34",
"CountryCodes": {
"tld": "es",
"iso3": "ESP",
"iso2": "ES",
"fips": "SP",
"isoN": 724
},
"CountryInfo": "http://www.geognos.com/geo/en/cc/es.html"
},
I didn't look but perhaps they have cities per country info.
It's also a shame they don't include the native language(s) that are spoken but hey, it's still a good resource.
P.S. I know you asked for YAML, but you can use JSON in Ruby and there are also YAML/JSON converters about.