How to install and configure Foreman on CentOS 7 or RHEL 7

1. Introduction

Foreman is an open source tool that can help with the management of servers, by providing an easy way to interact with Puppet (or Chef) to automate tasks and application deployment. Foreman provides a robust web user interface, API, and CLI which can be used to provision, configure, and monitor your servers. It is suitable for infrastructures of all sizes, and works with most distributions of Linux.

In this tutorial, we will show you how to install Foreman with Puppet, and start using it to manage your servers. We will use Foreman for its reporting and External Node Classifier (ENC) capabilities, to ease the management of Puppet.

2. Features

  • Discover, provision and upgrade your entire bare-metal infrastructure
  • Create and manage instances across private and public clouds
  • Group your hosts and manage them in bulk, regardless of location
  • Review historical changes for auditing or troubleshooting
  • Extend as needed via a robust plugin architecture
  • Automatically build images (on each platform) per system definition to optimize deployment

3. Operating System

This article is based on RHEL 7 / CentOS 7 .

4. Prerequisites

Before installing Foreman, make sure you have setup a hostname and its dns properly for your server. You can edit the file /etc/hosts and update it as follows:( it is an example )

138.201.3.24 sapin-centos7.syslint.com  sapin-centos7

Also update the hostname file too inside /etc/hostname

sapin-centos7.syslint.com

5. Install Foreman on CentOS 7 / RHEL 7

Foreman can be installed in different methods. The recommended way is with the puppet based Foreman Installer but you may also use your distribution’s package manager or install directly from source.

The Foreman installer is a collection of Puppet modules that installs everything required for a full working Foreman setup. It uses native OS packaging (e.g. RPM and .deb packages) and adds necessary configuration for the complete installation.

The Foreman installer will install the necessary components such as the Foreman web UI, Smart Proxy, Passenger (for the puppet master and Foreman itself), and optionally TFTP, DNS and DHCP servers.

5.1. Configure EPEL, Puppet and Foreman repositories

Please run the below command for enabling the EPEL , pupet and forman repos.

# rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
#rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm
#rpm -ivh http://yum.theforeman.org/releases/1.9/el7/x86_64/foreman-release.rpm

Enable the RHEL Optional and RHSCL repos on RHEL 7 ### run the below command.

# yum-config-manager --enable rhel-7-server-optional-rpms rhel-server-rhscl-7-rpms

5.2. Download Foreman installer

Run the following command to download Foreman installer.

# yum -y install foreman-installer

5.3. Start installation of foreman

# foreman-installer

Once the installation is completed, you will see an output like below where you would find the initial username and password to access the Foreman.

Installing  Done    [100%][.................................................]
  Success!
  * Foreman is running at https://sapin-centos7.syslint.com
      Initial credentials are admin / KMq5Eoo8KHVtQPeh
  * Foreman Proxy is running at https://sapin-centos7.syslint.com:8443
  * Puppetmaster is running at port 8140
  The full log is at /var/log/foreman-installer/foreman-installer.log

Note down initial username and password, you need this for accessing Foreman’s dashboard.

Username :: admin
Password :: testpas

5.4. Configure Foreman (Optional)

If your Foreman host is not visible in Hosts –> All Hosts tab, you should run below command which will send the first Puppet report to Foreman, automatically creating the host in Foreman’s database.

# puppet agent --test

You will get an out like below

Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for sapin-centos7.syslint.com
Info: Applying configuration version '1452312143'
Notice: Finished catalog run in 0.08 seconds

Puppet 3+ will show a warning the first time that the node can’t be found, this can be ignored.

6. Access Foreman Web Console

You can access the Foreman via web browser https://your-ip-address or https://FQDN

You should get login page, enter your Foreman credentials.

forman-login

To list down the available hosts, goto Hosts –> All Hosts from Menu. Since we do not have any puppet clients, All Hosts tab would only list your Foreman host, with an “O” status. This indicates its status is OK, with no changes made on the last Puppet run. If your Foreman host is not shown here, check out configuring Foreman.

host formam

7. Download and Install NTP module

One of the more important requirement of puppet is to have an accurate time-keeping, to do this, we will install Puppet NTP module for managing the NTP service.

If you have Puppet 2.7.14 or higher, install the module automatically from Puppet Forge to our “production” environment (the default).

Use following command to install NTP module on Foreman (Puppet master) host.

# puppet module install -i /etc/puppet/environments/production/modules saz/ntp

You will get the below out.

Notice: Preparing to install into /etc/puppet/environments/production/modules ...
Notice: Downloading from https://forgeapi.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/etc/puppet/environments/production/modules
└── saz-ntp (v2.3.2)

In Foreman’s web console, go to Configure > Puppet Classes and click Import from hostname (sapin-centos7.syslint.com) to read the available Puppet classes from the puppet master and populate Foreman’s database.

puppet class

Select the NTP module and click the update button.

puppet-change

After clicking the update button, you will see something like below. The “ntp” class will appear in the Puppet class list if installed correctly. Click on First NTP class on the left.

ntp

Now, Click the Smart Class Parameter and then select server list on the left side. Tick the Override checkbox so Foreman manages the “server list” parameter of the class, then click Submit.

Forman-server-list

Go to Hosts –> All Hosts, edit the Foreman host.

forman-host

Go to Puppet Classes tab and expand the ntp module and click the + icon to add the ntp class to the host, then click submit.

This time, it will take you automatically to the host details page. Click on YAML, it will show the ntp class and the server list parameter, as passed to Puppet via the ENC (external node classifier) interface.

puppet-runtime

At last, run the following command on the Foreman host to see the NTP service automatically reconfigured by Puppet and the NTP module.

# puppet agent --test

Verify the installation of NTP module by going to Hosts –> All Hosts –> Select Foreman Host –> Reports –> Select latest report.

forman-report

8. Conclusion

———-

We have successfully configured Foreman and now it is ready to accept agents / nodes. It’s time to add some new hosts to Foreman.

9. Reference.

http://theforeman.org/manuals/1.10/index.html

5 Replies to “How to install and configure Foreman on CentOS 7 or RHEL 7”

  1. Hello.

    I have a doubt about this: do you enable rhel-7-server-optional-rpms rhel-server-rhscl-7-rpms in a CentOS server? I know this works with RHEL7 (obviously), but in CentOS?

  2. The article is extremely good. I need to use and deploy servers on the fly using vmware. How do i do that

  3. 100% your article will not work

    My test: centos7.7

    Error
    Running Start Services
    ================================================================================
    Check if command is run as root user: [OK]
    ——————————————————————————–
    Start applicable services:
    Starting the following service(s):
    postgresql
    / All services started [OK]
    ——————————————————————————–

    foreman-maintain service start –only=postgresql finished successfully!
    Running Stop Services
    ================================================================================
    Check if command is run as root user: [OK]
    ——————————————————————————–
    Stop applicable services:
    Stopping the following service(s): [FAIL]
    No services found matching your parameters
    ——————————————————————————–
    Scenario [Stop Services] failed.

    The following steps ended up in failing state:

    [service-stop]

    Resolve the failed steps and rerun
    the command. In case the failures are false positives,
    use –whitelist=”service-stop”

    foreman-maintain service stop failed! Check the output for error!
    [ERROR 2020-05-12T22:25:07 verbose] foreman-maintain service stop failed! Check the output for error!
    [ INFO 2020-05-12T22:25:07 verbose] Installer finished in 29.183254494 seconds

  4. unable to find content management tab in foreman after successful installation. Kindly check and update what exactly need to be installed for the content tab to be visible in the foreman home page.

Leave a Reply to Subash Cancel reply

Your email address will not be published.