This can just be `Array(hosts).each do |h|` and then you can get rid of the above if/else.