{"id":385,"date":"2021-04-23T12:56:49","date_gmt":"2021-04-23T12:56:49","guid":{"rendered":"http:\/\/thomas.goirand.fr\/blog\/?p=385"},"modified":"2021-04-23T12:56:49","modified_gmt":"2021-04-23T12:56:49","slug":"puppet-and-os-detection","status":"publish","type":"post","link":"http:\/\/thomas.goirand.fr\/blog\/?p=385","title":{"rendered":"Puppet and OS detection"},"content":{"rendered":"\n<p>As you may know, Puppet uses &#8220;facter&#8221; to get facts about the machine it is about to configure. That&#8217;s fine, and a nice concept. One can later use variables in a puppet manifest to do different things depending on what facter tells. For example, the operating system name &#8230; oh no! This thing is really stupid &#8230; Here&#8217;s the code one has to do to be compatible with puppet from version 3 up to 5:<\/p>\n\n\n\n<p><code>if $::lsbdistcodename == undef{<br>  # This works around differences between facter versions<br>  if $facts['os']['lsb'] != undef{<br>    $distro_codename = $facts['os']['lsb']['distcodename']<br>  }else{<br>    $distro_codename = $facts['os']['distro']['codename']<br>  }<br>}else{<br>  $distro_codename = downcase($::lsbdistcodename)<br>}<\/code><\/p>\n\n\n\n<p>Indeed, the global variable $::lsbdistcodename still existed up to Stretch (and is gone in Buster). The global $::facts wasn&#8217;t an array before (but a hash), so in Jessie, it breaks with the error message &#8220;facts is not a hash or array when accessing it with os&#8221;. So, one need the full code above to make this work.<\/p>\n\n\n\n<p>It&#8217;s ok to improve things. It is <strong>NOT OK<\/strong> to break os detection. To me it is a very bad practice from upstream Puppet authors. I&#8217;m publishing this in the hope to avoid others to fall in the same trap as I did.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As you may know, Puppet uses &#8220;facter&#8221; to get facts about the machine it is about to configure. That&#8217;s fine, and a nice concept. One can later use variables in a puppet manifest to do different things depending on what facter tells. For example, the operating system name &#8230; oh no! This thing is really [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/thomas.goirand.fr\/blog\/index.php?rest_route=\/wp\/v2\/posts\/385"}],"collection":[{"href":"http:\/\/thomas.goirand.fr\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/thomas.goirand.fr\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/thomas.goirand.fr\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/thomas.goirand.fr\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=385"}],"version-history":[{"count":1,"href":"http:\/\/thomas.goirand.fr\/blog\/index.php?rest_route=\/wp\/v2\/posts\/385\/revisions"}],"predecessor-version":[{"id":386,"href":"http:\/\/thomas.goirand.fr\/blog\/index.php?rest_route=\/wp\/v2\/posts\/385\/revisions\/386"}],"wp:attachment":[{"href":"http:\/\/thomas.goirand.fr\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/thomas.goirand.fr\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=385"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/thomas.goirand.fr\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}