Commit 0ef09f45 authored by Cool Fire's avatar Cool Fire
Browse files

Add information about Vagrant and testing

parent 51d71737
Pipeline #618 passed with stages
in 9 minutes and 32 seconds
Keep track of the Puppetfile and lockfile
# Setting up
## Branches and forks
Always work from your own fork of the repos. Fork them to your own namespace and clone them from there to work on stuff. Make your changes in a new branch and submit any changes you've made back to the main repositories in a merge request. Always make sure any YAML files you submit pass yamllint checks and any puppet code passes puppetlint and puppet parser syntax checks. See the `.gitlab-ci.yml` file in each repository for the exact checks that it will need to pass.
## Repository structures
This is the base repository, the `manifests`, `modules`, and `hieradata` repos need to be cloned inside this direcotry. If you do not have access to the `hieradata` repository, you can use the `hieradata-testing` repo instead.
To ensure our puppet install can find our hieradata you need to create the file "hiera.yaml". We use the following config
version: 5
datadir: hieradata
data_hash: yaml_data
- name: "YAML hierarchy levels"
- "node/%{facts.fqdn}.yaml"
- "domain/%{facts.domain}.yaml"
- "osfamily/%{}.yaml"
- "common.yaml"
Paste this into your hiera.yaml file and your hieradata structure should be compatible with ours.
# Testing
Vagrant and Virtualbox are used for testing changes. Changes are tested on the debian/stretch64 image.
## Setting up a new vagrant box
If you are already using vagrant and know how to configure a box, you can skip this.
First make sure you have both virtualbox and vagrant installed of course, then to create a new vagrant box run the following commands
vagrant init debian/stretch64
vagrant up
This will set up a new Vagrantfile and download the box for you. Once this is done run `vagrant halt` to stop the VM again, since we need to make some tweaks to the Vagrantfile in order to make it work with puppet. If your Vagrantfile was newly generated by the vagrant init command you can use this one instead, otherwise make sure you add any missing config options to your existing Vagrantfile.
Vagrant.configure(2) do |config| = "debian/stretch64"
config.vm.synced_folder "hieradata", "/tmp/vagrant-puppet/hieradata"
config.vm.provision "puppet", :options => ["--yamldir /hieradata"] do |puppet|
puppet.hiera_config_path = "hiera.yaml"
puppet.working_directory = "/tmp/vagrant-puppet"
puppet.module_path = "modules"
puppet.options = "--verbose"
If you do not have a default.pp manifest, create a blank one now.
touch manifests/default.pp
The vagrant box still needs to have the Virtualbox guest additions installed in order to automatically mount our puppet code repositories and intergrate nicely, so we now have to start the Virtualbox GUI and run our puppet VM. It should be called something like `puppet_default_[some big number]`.
First we need to give it a CD drive to instert the image into. Open the VM's settings, go to "Storage" and click the SATA controller and then the "Add optical drive" button that appears next to it. You can pick the "Leave empty" option when it asks you for a disk image.
You can now start the VM as you would any other Virtualbox VM. Let it boot and log in with the default credentials. (User: vagrant, pass: vagrant). Now form the Virtualbox "Devices" menu, pick the "Insert Guest additions CD image..." option. Now we can mount it inside our virualbox VM. We'll mount it to /mnt for now because we're lazy and it's easy.
sudo mount /dev/sr0 /mnt
First we need to install a few dependencies for the guest additions installer to run.
sudo apt install gcc make perl linux-headers-amd64
Once that is done we can run the Virtualbox Guest additions installer.
sudo /mnt/
Once that is finished too, we finally have a Virtualbox image that will work with our puppet install! You can run `sudo shutdown` from the Virtualbox console window to stop the VM. You can also take this moment to remove the CD drive from the VM again, but you don't have to, it should not interfere with anything.
Since we don't want to do this again, this would also be a great time to take a snapshot of the VM so we can roll back to it again later in case anything breaks. You can do this directly from the Virtualbox GUI. (You can also do it from vagrant, but the GUI is just a nice simple click.)
Now lets test our vagrant box. Run `vagrant up` from your terminal and make sure you are in the same directory as you Vagrantfile and the base of the puppet repo. If all goes well it should boot in a few seconds.
Now we'll connect to the VM over ssh. Use the `vagrant ssh` command, this should drop you into an ssh session inside the VM.
While we're in here, there is one more thing to configure. Since the Vagrant user uses uid 1000 by default, this may conflict with any users we want to provision using puppet so we will change the UID of vagrant to 500 instead. Since this is just a VM we don't care about doing it all neat and clean so we can just edit the `/etc/passwd` and `/etc/group` files but before anything else we need to make sure we'll still have access to our SSH key when the new UID is set.
sudo chown -R 500:500 /home/vagrant
Now we can change the GID and UID
sed 's/1000/500/g' /etc/group | sudo tee /etc/group
sed 's/1000/500/g' /etc/passwd | sudo tee /etc/passwd
Now we need to log out and `vagrant ssh` back in to see if our changes worked. Once you log back in and run the `id` command you should see you now have uid 500. Take another snapshot of the VM here just to be safe.
All that is left to do now is to install puppet inside of the VM so we can provision stuff in there. We'll download and install the latest Puppet 5 repo package and use that to install puppet.
sudo dpkg -i puppet5-release-stretch.deb
sudo apt update
sudo apt install puppet-agent
GREAT! That's finally all we need to do to start testing stuff in vagrant. We'll shut down the VM and make another snapshot of the VM here so we never have to do this ever again.
## Testing puppet code inside vagrant
Now that we've spent an hour setting up a vagrant box, let's test some code! Run `vagrant up` to start your VM, then run `vagrant provision` to have puppet provision the VM. Exciting! But it doesn't seem to do much yet. This is because we've not told it to do anything yet so we'll include a profile. Edit the "manifests/default.pp" file to `include ::role::something` or `::profile::something` you are working on. From this point onward you should be ready to write and test your puppet code!
If you are missing any of the stanard puppet libraries, you can install them using librarian-puppet
librarian-puppet install
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment