title | description | author | tags | date_published |
---|---|---|---|---|
Set up a Puppet master and agent configuration in Compute Engine |
Learn how to configure Compute Engine instances as a Puppet master and agent, and use a manifest to deploy an application from the master to the agent. |
ksakib |
Puppet, Google Cloud, Compute Engine, Puppet Master, Puppet Agent |
2018-06-11 |
Contributed by the Google Cloud community. Not official Google documentation.
- Set up the virtual machines
- Install and run Puppet master
- Install Puppet agent and request a certificate from the master
- Sign the certificate to establish communication between the Puppet master and Puppet agent
- Write a manifest for a simple web app and deploy it to the Puppet agent
-
Create a small(1 shared vCPU + 1.7 GB memory) Compute Engine instance with the OS Ubuntu 16.04 xenial and with 'Allow HTTP traffic' option checked under Firewall section and name is puppet-agent.
-
Create another Compute Engine instance but this time a with 1 vCPU + 3.75 GB memory with the same OS (Ubuntu 16.04 xenial). Keep the default firewall option. No need to check http or https. Name the instance as puppet-master.
-
SSH into the puppet-master instance, then run the following commands to install the Puppet server:
wget https://apt.puppetlabs.com/puppetlabs-release-pc1-xenial.deb sudo dpkg -i puppetlabs-release-pc1-xenial.deb sudo apt-get update sudo apt-get install puppetserver
-
Start the Puppet server by running the following command:
sudo systemctl start puppetserver
-
Make sure the Puppet server has started by running the following command:
sudo systemctl status puppetserver
You should see a see a line that says "active (running)" in the result.
-
Configure the Puppet server to start at boot by running the following command:
sudo systemctl enable puppetserver
-
SSH into the puppet-agent instance, then run the following commands to install the Puppet agent:
wget https://apt.puppetlabs.com/puppetlabs-release-pc1-xenial.deb sudo dpkg -i puppetlabs-release-pc1-xenial.deb sudo apt-get update sudo apt-get install puppet-agent
-
Before starting Puppet agent, edit the /etc/hosts file to identify the Puppet master to use to request the certificate. At the end of the file, specify the internal IP address of the puppet-master Compute Engine instance, as shown following:
[PUPPET_MASTER_COMPUTE_ENGINE_INSTANCE_INTERNAL_IP_ADDRESS] Puppet
You can get the internal IP address of the puppet-master Compute Engine instance from the VM instances page in the Cloud Console. 3. Run the following commands to run the Puppet agent:
sudo systemctl start puppet
sudo systemctl enable puppet
-
The first time the Puppet agent runs, it sends a certificate signing request to the Puppet master. To list all unsigned certificate requests, run the following command on the puppet-master instance:
sudo /opt/puppetlabs/bin/puppet cert list
-
We'll use the --all option to sign certificate:
sudo /opt/puppetlabs/bin/puppet cert sign --all
You can also do a single sign by
sudo /opt/puppetlabs/bin/puppet cert sign puppet-agent.c.YOUR_PROJECT_ID.internal
-
On the puppet-master instance, navigate to the folder /etc/puppetlabs/code/environments/production/manifests/, make a manifest file named site.pp, and copy the following code into it:
node /agent/{ include webserver }
-
Navigate to the /etc/puppetlabs/code/environments/production/modules directory and make a new directory by running the following command:
sudo mkdir -p webserver/manifests
-
In the new manifests directory, create a file named init.pp, and copy the following code into it:
class webserver { package { 'apache2': ensure => present } file {'/var/www/html/index.html': # resource type file and filename ensure => present, # make sure it exists content => "<h1>This page is installed from Puppet Master</h1>", # content of the file } }
-
Run the following command on the puppet-agent instance to get the catalog from the Puppet master and apply the manifest:
sudo /opt/puppetlabs/bin/puppet agent --test
-
Copy the external IP address of the puppet-agent instance (you can get this from the VM instances page in the Cloud Console) and paste it into your browser. You should see a web page with the message "This page is installed from Puppet Master".