I created mCollective inventory script as below,
def formatting(users_ids)
YAML.load(File.open(users_ids))
end
inventory do
format "%s\t%s\t"
fields { [facts["hostname"], formatting(facts["users_ids"]) ] }
end
Here users_ids facter is in yaml format on the server. So when I do inventory for this facter I need to parse that yaml format to hash. But when I run with this script getting below error,
[root@mco-server]#
The inventory application failed to run, use -v for full error backtrace details: (eval):2:in `initialize': No such file or directory - ---
root: 0
test1: 503
testuser: 2033
[root@mco-server]#
Not sure if am missing something to get the output parsed. The strange thing is its not printing hostname also.
The facter output is below on the server from facts.yaml
users_ids: |-
---
root: 0
test1: 503
testuser: 2033
Any help would be much appreciated.
According to the error message, the argument you are passing to
users_idsis not a valid filename.Somehow your code is passing
---as an argument to that method. This is likely due to the combination of your API calls to parse and load the yaml and the yaml file itself. Consider changing the API call to a cleaner:and I think you really want a hash in your yaml and not an array of key-value pairs with an element of
---, so your yaml should really be:which would also remove the
---which typically indicates the beginning of a yaml, and also seems to be what your code is erroring on in the way you are trying to load the yaml.