<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andrew Jones</title>
    <description>The latest articles on DEV Community by Andrew Jones (@16c7x).</description>
    <link>https://dev.to/16c7x</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1581003%2Fe2d38b46-6886-454a-b800-f5a38f36b3f2.jpeg</url>
      <title>DEV Community: Andrew Jones</title>
      <link>https://dev.to/16c7x</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/16c7x"/>
    <language>en</language>
    <item>
      <title>Puppet 8 readiness with Onceover</title>
      <dc:creator>Andrew Jones</dc:creator>
      <pubDate>Thu, 06 Jun 2024 08:29:15 +0000</pubDate>
      <link>https://dev.to/puppet/puppet-8-readiness-with-onceover-135f</link>
      <guid>https://dev.to/puppet/puppet-8-readiness-with-onceover-135f</guid>
      <description>&lt;p&gt;Puppet 8 has been released, with it comes security enhancements, the dropping of deprecated features, and performance improvements, you can read more about Puppet 8 on this &lt;a href="https://www.puppet.com/blog/puppet-8" rel="noopener noreferrer"&gt;blog post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this blog post, well look at how you can take your existing Puppet 7 code and use &lt;a href="https://github.com/voxpupuli/onceover" rel="noopener noreferrer"&gt;Onceover&lt;/a&gt;, a free testing tool, to test it against Puppet 8 to prepare for your migration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Puppet 8
&lt;/h2&gt;

&lt;p&gt;Of the many changes to Puppet 8, a few will have a direct impact on your current Puppet code.&lt;br&gt;
Strict mode will now be enforced, for example, in Puppet 7 you could add a string to an integer, &lt;code&gt;"1" + 1&lt;/code&gt;, this will now fail.&lt;br&gt;
Legacy facts, which have been deprecated for some time, have been removed. &lt;br&gt;
Hiera 3 has also been removed.&lt;/p&gt;
&lt;h2&gt;
  
  
  Onceover
&lt;/h2&gt;

&lt;p&gt;The simple question we want to answer is "will my Puppet 7 code compile into a catalog on Puppet 8" and for that, &lt;a href="https://github.com/voxpupuli/onceover" rel="noopener noreferrer"&gt;Onceover&lt;/a&gt; is the perfect tool. If you haven't used &lt;a href="https://github.com/voxpupuli/onceover" rel="noopener noreferrer"&gt;Onceover&lt;/a&gt; before, it's a stand alone tool that you can run on any machine, and test that the roles and profiles in your control-repo will compile into catalogs.&lt;/p&gt;
&lt;h3&gt;
  
  
  Install Ruby 3
&lt;/h3&gt;

&lt;p&gt;The first thing we'll need to do is install Ruby 3, it's a requirement of Puppet 8. Follow these steps to install it &lt;a href="https://www.ruby-lang.org/en/documentation/installation/" rel="noopener noreferrer"&gt;Installing Ruby&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you're on your own workstation you may want to consider using &lt;a href="https://github.com/rbenv/rbenv" rel="noopener noreferrer"&gt;rbenv&lt;/a&gt; to allow you to quickly switch between versions of Ruby that your other project may depend upon.&lt;/p&gt;
&lt;h3&gt;
  
  
  Install Onceover
&lt;/h3&gt;

&lt;p&gt;The first step in installing &lt;a href="https://github.com/voxpupuli/onceover" rel="noopener noreferrer"&gt;Onceover&lt;/a&gt; is to clone your control-repo onto your system.&lt;/p&gt;

&lt;p&gt;Then install bundler &lt;code&gt;gem install bundler&lt;/code&gt;; this is required to read the Gemfile we'll produce in the next step to install the required Gems.&lt;/p&gt;

&lt;p&gt;In the root of your control-repo create a Gemfile, this specifies the main Gems we want to install and their versions. If you wanted to use a different version of Puppet, just change the version in the Gemfile. If you host Gems internally such as Artifactory, you can specify the source in here too.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Gemfile
source "https://rubygems.org"
gem 'puppet', '~&amp;gt; 8.4'
gem 'onceover', '~&amp;gt; 3.22'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run &lt;code&gt;bundle install&lt;/code&gt; to install all the gems and their dependencies.&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;bundle exec onceover init&lt;/code&gt; to initialise the control-repo, one of the things this does is create the .onceover directory and puts the &lt;a href="https://github.com/voxpupuli/onceover" rel="noopener noreferrer"&gt;Onceover&lt;/a&gt; config file, onceover.yaml, into the spec directory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Run a test
&lt;/h3&gt;

&lt;p&gt;To keep things simple, my control-repo contains one role.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# site-modules/role/manifests/example.pp
class role::example {
  include profile::coercion.pp
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that role will contain one profile, this profile contains some code that would compile a catalog under Puppet 7, but not under Puppet 8.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# site-modules/profile/manifests/coercion.pp
class profile::coercion {
  $result = '1' + 1
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last job is to modify the &lt;a href="https://github.com/voxpupuli/onceover" rel="noopener noreferrer"&gt;Onceover&lt;/a&gt; configutation file, to keep this simple I just want it to compile the example role on Ubuntu 20.04.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;classes:
  - role::example

nodes:
  - Ubuntu-20.04-64

node_groups:
  non_windows_nodes:
    - Ubuntu-20.04-64

test_matrix:
  - all_nodes:
      classes: 'all_classes'
      tests: 'spec'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finaly, to run the test, run &lt;code&gt;onceover run spec&lt;/code&gt;.&lt;br&gt;
This will return the following error, which is expected, as Puppet 8 enforces &lt;a href="https://www.puppet.com/docs/puppet/8/upgrading-from-puppet7-to-puppet8.html#upgrading-from-puppet7-to-puppet8-legacy-strict-mode" rel="noopener noreferrer"&gt;strict mode&lt;/a&gt; on coercion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;role::example: F

role::example: failed
  errors:
    Evaluation Error: The string '1' was automatically coerced to the numerical value 1
      file: site-modules/profile/manifests/coercion.pp
      line: 3
      column: 13
      factsets: Ubuntu-20.04-64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Refactor our code and rerun the test
&lt;/h3&gt;

&lt;p&gt;The error is reasonably clear, we provided a string and it was used as an integer. Lets fix that code!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# site-modules/profile/manifests/coercion.pp
class profile::coercion {
  $result = 1 + 1
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is a pass!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;role::example: P
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Using &lt;a href="https://github.com/voxpupuli/onceover" rel="noopener noreferrer"&gt;Onceover&lt;/a&gt; and the Puppet 8 Gem, we can quickly detect code that will not work on Puppet 8 and we can do this on a test machine or laptop, well away from our Puppet servers and production environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  A note on Continuous Delivery for Puppet Enterprise (CD4PE)
&lt;/h2&gt;

&lt;p&gt;If you're using &lt;a href="https://help.puppet.com/cdpe/" rel="noopener noreferrer"&gt;Continuous Delivery&lt;/a&gt; you're probably already using &lt;a href="https://github.com/voxpupuli/onceover" rel="noopener noreferrer"&gt;Onceover&lt;/a&gt; on the &lt;a href="https://hub.docker.com/r/puppet/puppet-dev-tools/tags" rel="noopener noreferrer"&gt;puppet-dev-tools:4.x&lt;/a&gt; container that ships with &lt;a href="https://help.puppet.com/cdpe/" rel="noopener noreferrer"&gt;Continuous Delivery&lt;/a&gt;. To start testing against Puppet 8, duplicate the &lt;a href="https://github.com/voxpupuli/onceover" rel="noopener noreferrer"&gt;Onceover&lt;/a&gt; job you're already running, but change the Docker container it uses to &lt;a href="https://hub.docker.com/layers/puppet/puppet-dev-tools/puppet8/images/sha256-6da1c6cdde55a3b174a6042b0e724ce0340d146f616e4ea1853aee78d4e87677?context=explore" rel="noopener noreferrer"&gt;puppet-dev-tools:puppet8&lt;/a&gt;&lt;/p&gt;

</description>
      <category>puppet</category>
    </item>
  </channel>
</rss>
