Facter.add('root_ssh_key') do
  pubkey = '/root/.ssh/id_rsa.pub', 'C:/Users/Administrator/.ssh.pub'
  pubkey.each do |key|
    setcode do
      File.read(key).split[1] if File.exists? key
    end
  end
end

Facter.add('root_ssh_key') do
  pubkey = '/root/.ssh/id_rsa.pub', 'C:/Users/Administrator/.ssh.pub'
  pubkey.each do |key|
    if File.exists? key
      setcode do
        File.read(key).split[1]
      end
    end
  end
end

Move setcode Block Inside of Conditional
Move setcode Block Inside of Conditional

Otherwise the first attempt returns the value as undef
