0

Here is the manifest code which is failing:

each( $facts['partitions'] ) |$name, $device| {
  notice( "${facts['hostname']} has device ${name} with size ${device['size']}" )
}

The error:

[manifests]$puppet apply /vagrant/manifests/mountpoints.pp
Error: Evaluation Error: Operator '[]' is not applicable to an Undef Value. at /vagrant/manifests/mountpoints.pp:1:7 on node siy
Error: Evaluation Error: Operator '[]' is not applicable to an Undef Value. at /vagrant/manifests/mountpoints.pp:1:7 on node siy

The facter command works fine:

[manifests]$facter partitions
{"vda1"=>{"uuid"=>"050e1e34-39e6-4072-a03e-ae0bf90ba13a", "size"=>"41943040", "mount"=>"/", "label"=>"DOROOT", "filesystem"=>"ext4"}}

Puppet version is 3.8.7 on Ubuntu 14.04

Jay Rajput
  • 1,813
  • 17
  • 23
  • Your code is fine and works for me with Facter 2.4.6 and Puppet 4.7.0. For some reason it is not resolving `$facts['fact_key']` as a fact hash and instead seems to be treating it like something else. Are you having future parser issues again? – Matthew Schuchard Oct 30 '16 at 15:01
  • @Matt Schuchard, it looks like $partitions work fine, but not $facts['partitions']. As you said some issue with array usage. I do have parser equal to future in the puppet.conf. I will see if I can upgrade to puppet 4 and see if that fixes the issue. – Jay Rajput Oct 30 '16 at 15:11
  • `$::partitions` is the old syntax for facts inside of Puppet. I would definitely recommend switching to Puppet 4.5.3 or 4.6.2 for a modern stable version, especially since 3.8 is EOL by the end of the year. Also, that is a hash and not an array. Is your book explaining what that code is doing or just showing examples and expecting you to guess? – Matthew Schuchard Oct 30 '16 at 15:13

1 Answers1

3

Eventually found that puppet 3.x defaults the setting stringify_facts to true, which was causing the problem when the code tried to access $facts as an array.

From the pupppet documentation at https://docs.puppet.com/puppet/3.8/reference/deprecated_settings.html#stringifyfacts--true

This setting defaults to true, which disables structured facts and coerces all fact values to strings. You can enable structured facts by setting stringify_facts = false in puppet.conf on every agent node and Puppet master..

If you want to use $facts as an hash/structure, then the configuration options stringify_facts shall be set to false and trusted_node_data set to true. The behaviors represented by these configuration settings are the defaults in the puppet 4, and are necessary for a successful migration.

Magellan
  • 113
  • 9
Jay Rajput
  • 1,813
  • 17
  • 23
  • I had to set trusted_node_data = true in puppet 3.8 – Christian Mar 10 '17 at 15:08
  • One more issue! I set trusted_node_data = true and stringify_facts = false and the problem was Still not fixed for me. My solution was installing puppetlabs-stdlib . Without stdlib puppet can't do many things documentation claims it can do. – JohnDavid Jul 11 '18 at 19:59
  • @johndavid Correct. Unless you're writing your own modules entirely though, any Supported module is going to have stdlib as a dependency. – Magellan Aug 05 '18 at 19:00