--- slug: title: Template description: date: draft: true tags: categories: --- ## Intro In my homelab, I like to play with tools like Ansible and Terraform. The primary interface is the CLI, which I love, but sometimes a fancy web UI is nicer. After setting up my OPNsense cluster, I wanted a way to keep it up to date on a schedule. Automation means Ansible to me, but how do you automate and schedule playbooks? At work I use Red Hat Ansible Automation Platform, which is great, but overkill for my lab. That’s how I found Semaphore UI. Let’s see what it can do. --- ## What is Semaphore UI [Semaphore UI](https://semaphoreui.com/docs/) is a sleek web interface designed to run automation with tools like Ansible and Terraform, and even Bash, Powershell or Python scripts. Initially began as Ansible Semaphore, a web interface created to provide a simple front-end for running solely Ansible playbooks. Over time the community evolved the project into a multi-tool automation control plane. It is a self-contained Go application with minimal dependencies capable of using different database backend, such as PostgreSQL, MySQL, or BoltDB. --- ## Installation Semaphore UI supports several [installation](https://semaphoreui.com/docs/category/installation) methods: Docker, Kubernetes, package manager or simple binary file. I used Docker for my setup, you can see how I currently deploy application in this [post]({{< ref "post/16-how-I-deploy-application" >}}) Here my `docker-compose.yml` file I've configured using PostgreSQL: ```yaml services: semaphore: image: semaphoreui/semaphore:v2.16.45 container_name: semaphore_ui environment: - TZ=Europe/Paris - SEMAPHORE_DB_USER=${POSTGRES_USER} - SEMAPHORE_DB_PASS=${POSTGRES_PASSWORD} - SEMAPHORE_DB_HOST=postgres - SEMAPHORE_DB_PORT=5432 - SEMAPHORE_DB_DIALECT=postgres - SEMAPHORE_DB=${POSTGRES_DB} - SEMAPHORE_PLAYBOOK_PATH=/tmp/semaphore/ - SEMAPHORE_ADMIN_PASSWORD=${SEMAPHORE_ADMIN_PASSWORD} - SEMAPHORE_ADMIN_NAME=${SEMAPHORE_ADMIN_NAME} - SEMAPHORE_ADMIN_EMAIL=${SEMAPHORE_ADMIN_EMAIL} - SEMAPHORE_ADMIN=${SEMAPHORE_ADMIN} - SEMAPHORE_ACCESS_KEY_ENCRYPTION=${SEMAPHORE_ACCESS_KEY_ENCRYPTION} - SEMAPHORE_LDAP_ACTIVATED='no' # - SEMAPHORE_LDAP_HOST=dc01.local.example.com # - SEMAPHORE_LDAP_PORT='636' # - SEMAPHORE_LDAP_NEEDTLS='yes' # - SEMAPHORE_LDAP_DN_BIND='uid=bind_user,cn=users,cn=accounts,dc=local,dc=shiftsystems,dc=net' # - SEMAPHORE_LDAP_PASSWORD='ldap_bind_account_password' # - SEMAPHORE_LDAP_DN_SEARCH='dc=local,dc=example,dc=com' # - SEMAPHORE_LDAP_SEARCH_FILTER="(\u0026(uid=%s)(memberOf=cn=ipausers,cn=groups,cn=accounts,dc=local,dc=example,dc=com))" depends_on: - postgres networks: - backend - web labels: - traefik.enable=true - traefik.http.routers.semaphore.rule=Host(`semaphore.vezpi.com`) - traefik.http.routers.semaphore.entrypoints=https - traefik.http.routers.semaphore.tls.certresolver=letsencrypt - traefik.http.services.semaphore.loadbalancer.server.port=3000 restart: unless-stopped postgres: image: postgres:14 hostname: postgres container_name: semaphore_postgres volumes: - /appli/data/semaphore/db:/var/lib/postgresql/data environment: - POSTGRES_USER=${POSTGRES_USER} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - POSTGRES_DB=${POSTGRES_DB} networks: - backend restart: unless-stopped networks: backend: web: external: true ``` To generate the encrypting access keys, I use this command: ```bash head -c32 /dev/urandom | base64 ``` With Semaphore running, let’s take a quick tour of the UI and wire it up to a repo. --- ## Discovery After starting the stack, I could reach the login page at the URL:  To lo gin, I use the credentials defined by `SEMAPHORE_ADMIN_NAME`/`SEMAPHORE_ADMIN_PASSWORD`. On first login, Semaphore prompted me to create a project. I created the Homelab project:  The first thing I want to do is to add my *homelab* repository, you can find its mirror on Github [here](https://github.com/Vezpi/homelab). In `Repository`, I click the `New Repository` button, and add the repo URL. I don't specify credentials, the repo is public:  ℹ️ Before continue, I deploy 3 VMs for testing purpose: `sem01`, `sem02` and `sem03`. I deploy them using Terraform with [this project](https://github.com/Vezpi/Homelab/tree/main/terraform/projects/semaphore-vms). To interact with these VMs I need to configure credentials. In the the `Key Store`, I add the first credential, a SSH key for my user:  Then I create a new `Inventory`. I'm using the Ansible inventory format (the only one available). I select the SSH key previously created and select the type as `Static`. In the fields I enter the 3 hosts created with their FQDN:   ✅ Everything is now setup, I can move forward and test to run an Ansible playbook. --- ## Launching an Ansible playbook I want to test something simple, install a web server with a custom page on these 3 VMs, I create the playbook `install_nginx.yml`: ```yaml --- - name: Demo Playbook - Install Nginx and Serve Hostname Page hosts: all become: true tasks: - name: Ensure apt cache is updated ansible.builtin.apt: update_cache: true cache_valid_time: 3600 - name: Install nginx ansible.builtin.apt: name: nginx state: present - name: Create index.html with hostname ansible.builtin.copy: dest: /var/www/html/index.html content: |