2385 words
12 minutes

Install Foreman on Ubuntu Server

Cover image for Install Foreman on Ubuntu Server

This article is for those looking for a detailed and straightforward guide on installing Foreman on Ubuntu Server.

Foreman is open-source software for deploying, configuring and monitoring physical and virtual servers. Foreman can integrate with Ansible, Puppet, Chef, Salt and other configuration management software products.

IMPORTANT

OpenSSH must be installed on the server, and port 22 must be open in order to be able to connect to the server using the SSH protocol.

To install OpenSSH on a server, you can use the command:

Terminal window
sudo apt install openssh-server
NOTE

To connect to the server from a Windows system, you can use tools like PuTTY or MobaXterm.

NOTE

This guide walks you through connecting to a server with the iTerm2 terminal emulator on macOS.

CAUTION

You will need to open the following TCP ports for access to the services:

  • TCP port 80 - for the configuration deployment service.
  • TCP port 443 - to access the Foreman control panel.
  • TCP port 8140 - for Puppet Agent to work.
  • TCP port 5648 - for client and Smart Proxy operation.
  • TCP port 9090 - for communication with Smart Proxy.

We connect to the server on which you plan to install Foreman.

Let’s name the server using the command:

Terminal window
sudo hostnamectl set-hostname foreman.heyvaldemar.net

This tutorial uses foreman.heyvaldemar.net as the Foreman server name.

Install Foreman on Ubuntu Server - Step 1

The server with the agent installed must resolve the name of the Foreman server, and also the Foreman server must resolve the name of the client-server.

Make sure the server name has the correct DNS entry and also update the “/etc/hosts” file on the server with the command:

Terminal window
echo "10.170.18.186 foreman.heyvaldemar.net puppet.heyvaldemar.net foreman puppet" | sudo tee -a /etc/hosts

This tutorial uses foreman.heyvaldemar.net as the Foreman server name.

Install Foreman on Ubuntu Server - Step 2

Restart the hostamed service for the changes to the server name to take effect using the command:

Terminal window
sudo systemctl restart systemd-hostnamed

Install Foreman on Ubuntu Server - Step 3

Let’s check the correctness of the server name using the command:

Terminal window
hostname

Install Foreman on Ubuntu Server - Step 4

Now let’s replace the current shell process with a new one using the command:

Terminal window
exec bash

Install Foreman on Ubuntu Server - Step 5

Now you need to download and install the Puppet Server repository configuration package.

Download the Puppet Server repository configuration package using the command:

Terminal window
wget https://apt.puppetlabs.com/puppet6-release-bionic.deb

Install Foreman on Ubuntu Server - Step 6

Install the Puppet Server repository configuration package using the command:

Terminal window
sudo dpkg -i puppet6-release-bionic.deb

Install Foreman on Ubuntu Server - Step 7

Next, we connect the Foreman repository using the command:

Terminal window
echo "deb http://deb.theforeman.org/ bionic 2.4" | sudo tee /etc/apt/sources.list.d/foreman.list

Install Foreman on Ubuntu Server - Step 8

Next, connect the Foreman plugin repository using the command:

Terminal window
echo "deb http://deb.theforeman.org/ plugins 2.4" | sudo tee -a /etc/apt/sources.list.d/foreman.list

Install Foreman on Ubuntu Server - Step 9

Now let’s add the official Foreman key using the command:

Terminal window
wget -q https://deb.theforeman.org/pubkey.gpg -O- | sudo apt-key add -

Install Foreman on Ubuntu Server - Step 10

Update the local package index to the latest changes in the repositories using the command:

Terminal window
sudo apt update

Install Foreman on Ubuntu Server - Step 11

Now install Foreman Installer using the command:

Terminal window
sudo apt -y install foreman-installer

Install Foreman on Ubuntu Server - Step 12

Now install Foreman using the command:

Terminal window
sudo foreman-installer

Install Foreman on Ubuntu Server - Step 13

In the next step, you will receive the username and password of an account with Foreman administrator rights.

Save this data in a safe place.

Puppet binaries are located in the “/opt/puppetlabs/bin/” directory, which is not in the “PATH” environment variable by default and in the “secure_path” variable that is used for “sudo” operations.

NOTE

The path to the executable files is irrelevant for the Puppet services since the start of the services does not depend on the “PATH” and “secure_path”.

By adding the path to executable files to variables, you can use:

Terminal window
sudo puppet agent -t

Instead:

Terminal window
sudo /opt/puppetlabs/bin/puppet agent -t

Add the path to the Puppet executable files to the “secure_path” variable.

Open the “sudoers” configuration file in a text editor using the command:

Terminal window
sudo visudo

Install Foreman on Ubuntu Server - Step 14

Find the variable “secure_path”, and at the end of the line, before the closing quote, add the path to the Puppet executable files :/opt/puppetlabs/bin.

In order to save the changes in the “sudoers” file, press “Ctrl + x”.

Install Foreman on Ubuntu Server - Step 15

Now you need to confirm the changes in the file.

Click on the “y” button.

Install Foreman on Ubuntu Server - Step 16

Press the “Enter” button to confirm saving the file.

Install Foreman on Ubuntu Server - Step 17

Now let’s add the path to the Puppet executables to the “PATH” environment variable.

Open the “environment” configuration file in a text editor using the command:

Terminal window
sudo vim /etc/environment

Install Foreman on Ubuntu Server - Step 18

Press the “i” button to enter edit mode, and at the end of the line, before the closing quote, add the path to the Puppet executable files :/opt/puppetlabs/bin.

Install Foreman on Ubuntu Server - Step 19

Now press the “Esc” button to exit edit mode, then type "" and press the “Enter” button to save your changes and exit the editor.

Install Foreman on Ubuntu Server - Step 20

You can now install the NTP module to help you install, configure, and manage the NTP service on client operating systems.

Install the NTP module using the command:

Terminal window
sudo puppet module install puppetlabs-ntp -i /etc/puppetlabs/code/modules/

Install Foreman on Ubuntu Server - Step 21

Now you need to import the NTP module into your Foreman control panel.

From the workstation, go to the link https://foreman.heyvaldemar.net, where foreman.heyvaldemar.net is the name of my subdomain to access the Foreman control panel. You will need to specify your domain or subdomain through which your Foreman control panel will be accessible from the Internet.

This guide uses Mozilla Firefox as the web browser to connect to the Foreman Control Panel.

In the next step, you can see the warning “Warning: Potential Security Risk Ahead”.

Click on the “Advanced” button.

Install Foreman on Ubuntu Server - Step 22

Next, click on the “Accept the Risk and Continue” button.

Install Foreman on Ubuntu Server - Step 23

Default login for Foreman administrator account: admin

NOTE

The password for the administrator account was generated after the Foreman installation was completed.

Specify the username and password of an account with Foreman administrator rights, and click on the “Log in” button.

Install Foreman on Ubuntu Server - Step 24

From the menu on the left, select “Configure”, then “Classes”.

Install Foreman on Ubuntu Server - Step 25

Next, click on the button “Import environments from foreman.heyvaldemar.net.

This tutorial uses foreman.heyvaldemar.net as the Foreman server name.

Install Foreman on Ubuntu Server - Step 26

Select the environment for which you want to import the module, and click on the “Update” button.

Install Foreman on Ubuntu Server - Step 27

The module has been successfully imported into the selected environment.

Install Foreman on Ubuntu Server - Step 28

Next, we connect to the server on which you plan to install Puppet Agent.

Let’s name the server using the command:

Terminal window
sudo hostnamectl set-hostname puppet-agent.heyvaldemar.net

This tutorial uses puppet-agent.heyvaldemar.net as the name of the server with the Puppet agent installed.

Install Foreman on Ubuntu Server - Step 29

The server with the agent installed must resolve the name of the Foreman server, and also the Foreman server must resolve the name of the client-server.

Make sure the server name has the correct DNS entry and also update the “/etc/hosts” file with the IP address and client-server name using the command:

Terminal window
echo "10.170.18.152 puppet-agent.heyvaldemar.net puppet-agent" | sudo tee -a /etc/hosts

This tutorial uses puppet-agent.heyvaldemar.net as the name of the server with the Puppet agent installed.

Install Foreman on Ubuntu Server - Step 30

Next, add the IP address and name of the Foreman server to the “/etc/ hosts” file using the command:

Terminal window
echo "10.170.18.186 foreman.heyvaldemar.net puppet.heyvaldemar.net foreman puppet" | sudo tee -a /etc/hosts

The presence of this record will allow the server with the agent installed to resolve the Foreman server name even without a DNS record.

Install Foreman on Ubuntu Server - Step 31

Restart the hostamed service for the changes to the server name to take effect using the command:

Terminal window
sudo systemctl restart systemd-hostnamed

Install Foreman on Ubuntu Server - Step 32

Let’s check the correctness of the server name using the command:

Terminal window
hostname

Install Foreman on Ubuntu Server - Step 33

Now let’s replace the current shell process with a new one using the command:

Terminal window
exec bash

Install Foreman on Ubuntu Server - Step 34

Now you need to download and install the Puppet Agent repository configuration package.

Download the Puppet Agent repository configuration package using the command:

Terminal window
wget https://apt.puppetlabs.com/puppet6-release-bionic.deb

Install Foreman on Ubuntu Server - Step 35

Install the Puppet Agent repository configuration package using the command:

Terminal window
sudo dpkg -i puppet6-release-bionic.deb

Install Foreman on Ubuntu Server - Step 36

Update the local package index to the latest changes in the repositories using the command:

Terminal window
sudo apt update

Install Foreman on Ubuntu Server - Step 37

Now install Puppet Agent using the command:

Terminal window
sudo apt install -y puppet-agent

Install Foreman on Ubuntu Server - Step 38

Puppet binaries are located in the “/opt/puppetlabs/bin/” directory, which is not in the “PATH” environment variable by default and in the “secure_path” variable that is used for “sudo” operations.

NOTE

The path to the executable files is irrelevant for the Puppet services since the start of the services does not depend on the “PATH” and “secure_path”.

By adding the path to executable files to variables, you can use:

Terminal window
sudo puppet agent -t

Instead:

Terminal window
sudo /opt/puppetlabs/bin/puppet agent -t

Add the path to the Puppet executable files to the “secure_path” variable.

Open the “sudoers” configuration file in a text editor using the command:

Terminal window
sudo visudo

Install Foreman on Ubuntu Server - Step 39

Find the variable “secure_path”, and at the end of the line, before the closing quote, add the path to the Puppet executable files :/opt/puppetlabs/bin.

Install Foreman on Ubuntu Server - Step 40

Now you need to confirm the changes in the file.

Click on the “y” button.

Install Foreman on Ubuntu Server - Step 41

Press the “Enter” button to confirm saving the file.

Install Foreman on Ubuntu Server - Step 42

Now let’s add the path to the Puppet executables to the “PATH” environment variable.

Open the “environment” configuration file in a text editor using the command:

Terminal window
sudo vim /etc/environment

Install Foreman on Ubuntu Server - Step 43

Press the “i” button to enter edit mode, and at the end of the line, before the closing quote, add the path to the Puppet executable files :/opt/puppetlabs/bin.

Install Foreman on Ubuntu Server - Step 44

Now press the “Esc” button to exit edit mode, then type "" and press the “Enter” button to save your changes and exit the editor.

Install Foreman on Ubuntu Server - Step 45

Next, you need to make changes to the Puppet configuration file by opening it in a text editor using the command:

Terminal window
sudo vim /etc/puppetlabs/puppet/puppet.conf

Install Foreman on Ubuntu Server - Step 46

Press the “i” button to switch to edit mode, add a new section [main] with the following parameters:

[main]
certname = puppet-agent.heyvaldemar.net
server = foreman.heyvaldemar.net
environment = production
runinterval = 15m
NOTE

In this tutorial, Puppet Agent is installed on the puppet-agent.heyvaldemar.net server. You will need to specify your server through which your Puppet Agent will be accessible from the Internet or on the local network of your organization.

Foreman is also installed on the foreman.heyvaldemar.net server. You will need to specify your server through which your Foreman will be accessible from the Internet or from the local network of your organization.

NOTE

The “runinterval” parameter specifies the time interval between agent requests to the Foreman server.

Install Foreman on Ubuntu Server - Step 47

Now press the “Esc” button to exit edit mode, then type "" and press the “Enter” button to save your changes and exit the editor.

Install Foreman on Ubuntu Server - Step 48

Launch Puppet Agent and enable it to autostart when the operating system starts up using the command:

Terminal window
sudo puppet resource service puppet ensure=running enable=true

Install Foreman on Ubuntu Server - Step 49

Now you need to approve the certificate request for the server on which the Puppet Agent is installed so that the client can subsequently receive the configuration from the Foreman server.

Return to the Foreman control panel and select “Infrastructure” from the menu on the left, then “Smart Proxies”.

Install Foreman on Ubuntu Server - Step 50

Next, find the Foreman server, and in the “Actions” section, in the drop-down list, select “Certificates”.

This tutorial uses foreman.heyvaldemar.net as the Foreman server name.

Install Foreman on Ubuntu Server - Step 51

Now we find the client-server and in the “Actions” section, select “Sign”.

This tutorial uses puppet-agent.heyvaldemar.net as the name of the server with the Puppet agent installed.

Install Foreman on Ubuntu Server - Step 52

The certificate for the client-server has been successfully approved.

Install Foreman on Ubuntu Server - Step 53

You can now configure automatic certificate approval.

Go to the “Autosign entries” section and click on the “Create Autosign Entry” button.

Install Foreman on Ubuntu Server - Step 54

Next, you can specify the domain for which Foreman will automatically approve certificates.

NOTE

You must specify * Before the domain, so that all members of the specified domain will automatically approve certificates.

Click on the “Save” button.

Install Foreman on Ubuntu Server - Step 55

Automatic certificate approval is configured.

Install Foreman on Ubuntu Server - Step 56

We return to the server with the Puppet Agent installed.

Now you need to get the configuration for the client from the Puppet server using the command:

Terminal window
sudo puppet agent -t

Install Foreman on Ubuntu Server - Step 57

The configuration for the client from the Foreman server was successfully received.

Install Foreman on Ubuntu Server - Step 58


Social Channels#


Community of IT Experts#


Is this content AI-generated?

No. Every article on this blog is written by me personally, drawing on decades of hands-on IT experience and a genuine passion for technology.

I use AI tools exclusively to help polish grammar and ensure my technical guidance is as clear as possible. However, the core ideas, strategic insights, and step-by-step solutions are entirely my own, born from real-world work.

Because of this human-and-AI partnership, some detection tools might flag this content. You can be confident, though, that the expertise is authentic. My goal is to share road-tested knowledge you can trust.

Install Foreman on Ubuntu Server
https://www.heyvaldemar.com/install-foreman-on-ubuntu-server/
Author
Vladimir Mikhalev
Published at
2021-04-20
License
CC BY-NC-SA 4.0