0

I'm trying to write a fact for Puppet.

I have an array with usernames array = ["user1", "user2", "user3"] and then a code

array.each do |item|
    temp_data << Facter::Core::Execution.exec("net user #{item} /DOMAIN")
end
search_text = %r{comment|Local}
users_data = []
temp_data.each do |line|
    line.each_line do |num|
    users_data << (num) unless num =~ search_text
    end
end

temp_data generates fine, but I get an error ERROR puppetlabs.facter - error while resolving custom fact "winusers_domain": invalid byte sequence in UTF-8 but it doesn't show witch line the error is. Any suggestion?

mila002
  • 327
  • 3
  • 14

1 Answers1

0

I've figured it out so I answer to myself.

array.each do |item|
    temp_data << Facter::Core::Execution.exec("net user #{item} /DOMAIN")
end
search_text = %r{comment|Local}
users_data = []
temp_data.each do |line|
    line.encode!('UTF-16', 'UTF-8', :invalid => :replace, :replace => '')
    line.encode!('UTF-8', 'UTF-16')
    line.each_line do |num|
    users_data << (num) unless num =~ search_text
    end
end
mila002
  • 327
  • 3
  • 14