Unable to use $facts as a hash in the puppet manifest

醉酒当歌 提交于 2019-12-12 05:09:33

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/40330166/unable-to-use-facts-as-a-hash-in-the-puppet-manifest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!