Skip to content

Latest commit

 

History

History
97 lines (62 loc) · 3.11 KB

developing_on_ubuntu.md

File metadata and controls

97 lines (62 loc) · 3.11 KB

Developing on Ubuntu

Provisioning the Vagrant box

We're going to use Ubuntu 20.04 in this example so let's start by booting up our vagrant machine.

make ubuntu 2004 up

After the machine starts it will get bootstrapped for development. See the Vagrantfile for more information.

Note: there is a line in the vagrantfile that may need to be commented out depending on your setup, it has been marked so it is easy to find. As an additional note, the default ruby version for this box is currently set to v3.2.0, to change this simply update the relevant lines within the vagrantfile.

Let's start by accessing our new machine.

make ubuntu 2004 ssh

Clone your module

Once you have a remote ssh session established with your remote machine, open a new terminal and clone your module.

git clone https://github.com/puppetlabs/puppetlabs-motd
cd puppetlabs-motd

Making sure Git is authenticated

During bootstrap, gh-cli is installed. We can use it to authenticate git and persist our access tokens.

From a terminal run gh auth login and follow the instructions ensuring that you choose https when asked to choose a protocol.

.gitconfig and GPG

During the bootstrap, your .gitconfig and gpg keys will also have been copied over to the guest os.

Shared content folder

A shared content folder has been enabled for this image, simply place any files or modules you wish to be mirrored onto the vagrant box within ./ubuntu/2004/ and they will appear on the vagrant box.

Enter cd ../../vagrant/ upon from the initial ssh location to find them.

Install dependencies

From inside the module directory run bundle install. Gems will be saved locally to ./.bundle/gems.

bundle install

Once the dependencies have been installed we need to initialize the module for development.

bundle exec rake spec_prep

Underneath the spec/fixtures/ you should now have the following directories:

  • modules: spec/fixtures/modules
  • manifests: spec/fixtures/manifests

You can define test classes in spec/fixtures/manifests/site.pp. Alternatively, you can run any of the examples provided with the module.

Running Puppet

Running Puppet usually requires elevated privileges. This can cause a bit of complication when developing modules because of bundler requirements.

To make life easier, the bootstrap process installs rbenv sudo. It allows you to run elevated bundle exec commands.

Running the bundled version of Puppet with rbenv sudo would look like this

NOTE: May need to install bundler for sudo, i.e. rbenv sudo gem install bundler:2.1.4

rbenv sudo bundle exec puppet apply examples/example.pp --modulepath ./spec/fixtures/modules

For convenience, this has been wrapped in a function called puppet-apply and made available via the default bash profile.

puppet-apply ./spec/fixtures/manifests/site.pp --debug

You may see an error after running puppet-apply for the first time. If this happens, just install the version of bundler mentioned in the error message.

rbenv sudo gem install bundler:2.1.4