0

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.

Karthi1234
  • 949
  • 1
  • 8
  • 28
  • There already is an rpc plugin for inventory for mcollective. How are you trying to execute this script with mcollective? – Matthew Schuchard Oct 09 '16 at 01:12
  • Here is the command `mco inventory --script -I ` – Karthi1234 Oct 09 '16 at 08:13
  • Ok it is an addon to the inventory rpc plugin. Got it. – Matthew Schuchard Oct 09 '16 at 11:14
  • You should edit the post, remove non-essentials irrelevancies like "Any help would be much appreciated" and in include an interrogative sentence that is about programming ("Can someone help?" would be a question about people's capabilities, not about programming. Most questions that can be answered with just Yes/No are inappropriate.). – Anthon Oct 09 '16 at 18:06

1 Answers1

1

According to the error message, the argument you are passing to users_ids is not a valid filename.

def formatting(users_ids)
  YAML.load(File.open(users_ids))
end

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:

def formatting(users_ids)
  YAML.load_file(users_ids)
end

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:

users_ids:
  root: 0
  test1: 503
  testuser: 2033

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.

Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67