1

Let us say I have an array of values

["node1.example.org", "node2.example.org"]

And I want to pass this using facter, and use it in puppet at such:

host {
  $nodes:
     ...
}

How can I do this?

user3458168
  • 97
  • 1
  • 4

1 Answers1

5

Facter 1.x cannot pass structured data as fact values. All facts will be coerced into String format. This is especially unfortunate for Arrays, because those will have their elements concatenated without a join marker.

It is advisable to make your fact return a [comma] seperated list, e.g. instead of returning Array result, do

result * ","

In your manifest, turn this back into an array

$nodes_array = split($nodes, ',')
host { $nodes_array: }

See the Puppet function reference and Ruby's Array methods.

Facter 2 does support Boolean, Hash and Array facts, but this may not yet be readily available.

Felix Frank
  • 8,125
  • 1
  • 23
  • 30
  • We use facter-2.4.3 here already, but, when I set my custom fact to an array like ["a", "b"], Puppet manifest sees only "ab". Any ideas? Thanks! – Mikhail T. Apr 09 '16 at 20:21
  • 1
    @MikhailT. Yes, actually! Look for the `stringify_facts` option in Puppet `3.x`. It defaults to `true`, unfortunately. Most likely, you just want to add `stringify_facts=false` to your `puppet.conf`. – Felix Frank Apr 16 '16 at 19:12