Install Semaphore Ansible Web UI on CentOS 7|CentOS 8

ComputingPost
6 min readOct 21, 2022

--

In this guide, we will install Semaphore Ansible Web UI on CentOS 7|CentOS 8. Semaphore is an open source web-based solution that makes Ansible easy to use for IT teams of all kinds. It gives you a Web interface from where you can launch and manage Ansible Tasks.

Install Semaphore Ansible Web UI on CentOS 7|CentOS 8

Semaphore depends on the following tools:

  • MySQL >= 5.6.4/MariaDB >= 5.3
  • ansible
  • git >= 2.x

We will start the installation by ensuring these dependencies are installed on your CentOS 7|CentOS 8 server. So follow steps in the next sections to ensure all is set.

Before any installation we recommend you perform an update on the OS layer:

sudo yum -y update

A reboot is also essential once the upgrade is made:

sudo reboot -f

Step 1: Install MariaDB Database Server

We have a comprehensive guide on installation of MariaDB on CentOS 7|CentOS 8. Run the commands below to install the latest stable release of MariaDB database server.

curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup

sudo bash mariadb_repo_setup

sudo yum install MariaDB-server MariaDB-client MariaDB-backup

Start and enable mariadb database service:

sudo systemctl enable --now mariadb

Secure database server after installation:

$ sudo mariadb-secure-installation

Switch to unix_socket authentication [Y/n] n

Change the root password? [Y/n] y

Remove anonymous users? [Y/n] y

Disallow root login remotely? [Y/n] y

Remove test database and access to it? [Y/n] y

Reload privilege tables now? [Y/n] y

Step 2: Install git 2.x on CentOS 7|CentOS 8

Install git 2.x on your CentOS 7 server using our guide below.

Confirm git version.

$ git --version

git version 2.34.1

Step 3: Install Ansible on CentOS 7|CentOS 8

Install Ansible on your CentOS 7 server.

sudo yum -y install epel-release

sudo yum -y install ansible

Test if ansible command is available.

$ ansible --version

ansible 2.9.27

config file = /etc/ansible/ansible.cfg

configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']

ansible python module location = /usr/lib/python2.7/site-packages/ansible

executable location = /usr/bin/ansible

python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

Step 4: Download Semaphore

Visit the Semaphore Releases page and copy the download link for your OS.

sudo yum -y install wget curl

VER=$(curl -s https://api.github.com/repos/ansible-semaphore/semaphore/releases/latest|grep tag_name | cut -d '"' -f 4|sed 's/v//g')

wget https://github.com/ansible-semaphore/semaphore/releases/download/v$VER/semaphore_$VER_linux_amd64.rpm

Install Semaphore package:

$ sudo rpm -Uvh semaphore_$VER_linux_amd64.rpm

Preparing… ################################# [100%]

Updating / installing…

1:semaphore-0:2.8.53-1 ################################# [100%]

Check if you have semaphore binary in your $PATH.

$ which semaphore

/usr/bin/semaphore



$ semaphore version

v2.8.53

Usage help document:

$ semaphore  --help

Ansible Semaphore is a beautiful web UI for Ansible.

Source code is available at https://github.com/ansible-semaphore/semaphore.

Complete documentation is available at https://ansible-semaphore.com.



Usage:

semaphore [flags]

semaphore [command]



Available Commands:

completion generate the autocompletion script for the specified shell

help Help about any command

migrate Execute migrations

server Run in server mode

setup Perform interactive setup

upgrade Upgrade to latest stable version

user Manage users

version Print the version of Semaphore



Flags:

--config string Configuration file path

-h, --help help for semaphore



Use "semaphore [command] --help" for more information about a command.

Step 5: Setup Semaphore

Run the following command to start Semaphore setup in your system.

$ sudo semaphore setup

Hello! You will now be guided through a setup to:



1. Set up configuration for a MySQL/MariaDB database

2. Set up a path for your playbooks (auto-created)

3. Run database Migrations

4. Set up initial semaphore user & password



What database to use:

1 - MySQL

2 - BoltDB

3 - PostgreSQL

(default 1): 1

DB Hostname (default 127.0.0.1:3306):

DB User (default root): root

DB Password:

DB Name (default semaphore): semaphore

Playbook path (default /tmp/semaphore): /opt/semaphore

Web root URL (optional, example http://localhost:8010/): http://localhost:8010/

Enable email alerts (y/n, default n): n

Enable telegram alerts (y/n, default n): n

Enable LDAP authentication (y/n, default n): n

Confirm these values are correct to initiate setup.

Is this correct? (yes/no): yes

Config output directory (default /root):

WARN[0037] An input error occured:unexpected newline

Running: mkdir -p /root..

Configuration written to /root/config.json..

Pinging db..

Running DB Migrations..

Checking DB migrations

Creating migrations table

......

Migrations Finished

Set username

Username: admin

Email: admin@example.com

WARN[0268] sql: no rows in result set level=Warn

Your name: Admin User

Password: StrongUserPassword

You are all setup Admin User!

Re-launch this program pointing to the configuration file

./semaphore -config /root/config.json



To run as daemon:

nohup ./semaphore -config /root/config.json &

You can login with computingpost@example.com or computingpost.

You can set other configuration values on the file /root/config.json.

Step 6: Configure systemd unit for Semaphore

Let’s now configure Semaphore Ansible UI to be managed by systemd.

Create systemd service unit file.

sudo vi /etc/systemd/system/semaphore.service

The add:

[Unit]

Description=Semaphore Ansible UI

Documentation=https://github.com/ansible-semaphore/semaphore

Wants=network-online.target

After=network-online.target



[Service]

Type=simple

ExecReload=/bin/kill -HUP $MAINPID

ExecStart=/usr/bin/semaphore server --config /etc/semaphore/config.json

SyslogIdentifier=semaphore

Restart=always



[Install]

WantedBy=multi-user.target

Create Semaphore configurations directory:

sudo mkdir /etc/semaphore

Copy your configuration file to created directory:

sudo ln -s /root/config.json /etc/semaphore/config.json

Stop running instances of Semaphore.

sudo pkill semaphore

Confirm:

ps aux | grep semaphore

Reload systemd and start semaphore service.

sudo systemctl daemon-reload

sudo systemctl restart semaphore

Check status to see if running:

$ systemctl status semaphore

● semaphore.service - Semaphore Ansible UI

Loaded: loaded (/etc/systemd/system/semaphore.service; disabled; vendor preset: disabled)

Active: active (running) since Tue 2022-04-19 13:29:42 UTC; 3s ago

Docs: https://github.com/ansible-semaphore/semaphore

Main PID: 8636 (semaphore)

CGroup: /system.slice/semaphore.service

└─8636 /usr/bin/semaphore server --config /etc/semaphore/config.json



Apr 19 13:29:42 centos.example.com systemd[1]: Started Semaphore Ansible UI.

Apr 19 13:29:42 centos.example.com semaphore[8636]: MySQL root@127.0.0.1:3306 semaphore

Apr 19 13:29:42 centos.example.com semaphore[8636]: Tmp Path (projects home) /tmp/semaphore

Apr 19 13:29:42 centos.example.com semaphore[8636]: Semaphore v2.8.53

Apr 19 13:29:42 centos.example.com semaphore[8636]: Interface

Apr 19 13:29:42 centos.example.com semaphore[8636]: Port :3000

Apr 19 13:29:42 centos.example.com semaphore[8636]: Server is running

Set Service to start at boot.

$ sudo systemctl enable semaphore

Created symlink /etc/systemd/system/multi-user.target.wants/semaphore.service → /etc/systemd/system/semaphore.service.

Port 3000 should now be Open

$ sudo ss -tunelp | grep 3000

tcp LISTEN 0 128 [::]:3000 [::]:* users:(("semaphore",pid=8636,fd=8)) ino:36321 sk:ffff8ae3b4e59080 v6only:0 <->

Step 7: Setup Nginx Proxy (Optional)

To be able to access Semaphore Web interface with a domain name, use the guide below to setup.

Step 8: Access Semaphore Web interface

On your web browser, open semaphore Server IP on port 3000 or server name.

semaphore-ansible-ui-login

Use the username/email created earlier during installation to Sign in. Web console for semaphore should be shown after authentication.

semaphore-ansible-dashboard-1024x283

You’re ready to manage your servers with Ansible and powerful Web UI.

semaphore-ansible-ui-dashbord-start-1024x337

The initial steps required are:

  • Add SSH keys / API keys used by Ansible — Under Key Store > create key
semaphore-ansible-ui-add-ssh-keys-1024x556
  • Create Inventory file with servers to manage — Under Inventory > create inventory
semaphore-ansible-ui-add-inventory-1024x394
  • Create users and add to Team(s)
  • Create Environments
  • Add Playbook repositories
semaphore-ansible-create-repository
  • Create Task Templates and execute

Also check a detailed guide on semaphore Web UI.

For Ubuntu / Debian installation, check:

--

--

ComputingPost
ComputingPost

Written by ComputingPost

ComputingPost — Linux Howtos, Tutorials, Guides, News, Tips and Tricks.

No responses yet