# Ansible GUI

#### 簡介

Ansible是一套軟體工具，其可實現基礎架構即程式碼。它是開源的，並且該套件包括軟體供應、組態管理和應用程式部署等功能。 Ansible 最初由 Michael DeHaan 編寫，並於 2015 年被Red Hat收購，其旨在自動化設定類 Unix系統和Microsoft Windows 的環境。

#### Links

- Ansible Community 
    - [AWX for Docker](https://github.com/ansible/awx/blob/devel/tools/docker-compose/README.md)
    - [Documentation](https://docs.ansible.com/ansible/latest/getting_started/index.html)
- [How to Test Ansible Roles with Molecule and Docker](https://www.howtoforge.com/how-to-test-ansible-roles-with-molecule-and-docker/)
- Red Hat Ansible Automation Platform 
    - [Download](https://developers.redhat.com/products/ansible/download)
    - [Trial License](https://www.redhat.com/en/technologies/management/ansible/trial)
    - [Ansible Lightspeed with Watson Code Assistant](https://docs.ai.ansible.redhat.com/)  
        使用 IBM Watson Code Assistant 自動編寫 playbooks
    - [Setting up VSCoce and Ansible Lightspeed on Ubuntu 22.04](https://www.cyberciti.biz/programming/howto-setting-up-vscode-for-ansible-lightspeed-ai-in-ubuntu-22-04-desktop/)
- [Ansible Galaxy](https://galaxy.ansible.com/home)

#### Commands

```bash
# 列出 lookup 可用的 plugins
# Usage:
# motd_value: "{{ lookup('file', '/etc/motd') }}"
ansible-doc -l -t lookup
```

#### Ansible Semaphore

##### Links

- [https://www.ansible-semaphore.com/](https://www.ansible-semaphore.com/)
- [Github](https://github.com/ansible-semaphore/semaphore)
- [Docs](https://docs.ansible-semaphore.com/administration-guide/installation)
- \[Video\] [This web UI for Ansible is so damn useful!](https://www.youtube.com/watch?v=NyOSoLn5T5U)
- [Ansible Semaphore UI: My New Go-To Infrastructure Automation Tool - Virtualization Howto](https://www.virtualizationhowto.com/2025/07/ansible-semaphore-ui-my-new-go-to-infrastructure-automation-tool/)

##### Install with Docker

Create the directory

```bash
mkdir playbooks
mkdir config
chown 1001:1001 config
```

docker-compose.yml:

```yaml
---
volumes:
  semaphore-mysql:
    driver: local
services:
  mysql:
    image: mysql:8.0
    hostname: mysql
    volumes:
      - semaphore-mysql:/var/lib/mysql
    environment:
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
      - MYSQL_DATABASE=semaphore
      - MYSQL_USER=semaphore
      - MYSQL_PASSWORD=secret-password  # change!
    restart: unless-stopped
  semaphore:
    container_name: ansiblesemaphore
    image: semaphoreui/semaphore:v2.8.90
    user: 1001:1001 # change if needed
    ports:
      - 3000:3000
    environment:
      - SEMAPHORE_DB_USER=semaphore
      - SEMAPHORE_DB_PASS=secret-password  # change!
      - SEMAPHORE_DB_HOST=mysql
      - SEMAPHORE_DB_PORT=3306
      - SEMAPHORE_DB_DIALECT=mysql
      - SEMAPHORE_DB=semaphore
      - SEMAPHORE_ADMIN_PASSWORD=secret-admin-password  # change!
      - SEMAPHORE_ADMIN_NAME=admin
      - SEMAPHORE_ADMIN_EMAIL=admin@localhost
      - SEMAPHORE_ADMIN=admin
      - SEMAPHORE_ACCESS_KEY_ENCRYPTION=  # add to your access key encryption !
      - ANSIBLE_HOST_KEY_CHECKING=false  # (optional) change to true if you want to enable host key checking
    volumes:
      - ./inventory/:/inventory:ro
      - ./authorized-keys/:/authorized-keys:ro
      - ./config/:/etc/semaphore:rw
      - ./playbooks:/playbooks:ro
    restart: unless-stopped
    depends_on:
      - mysql
```

You must specify following confidential variables:

- `MYSQL_PASSWORD` and `SEMAPHORE_DB_PASS` — password for the MySQL user.
- `SEMAPHORE_ADMIN_PASSWORD` — password for the Semaphore's admin user.
- `SEMAPHORE_ACCESS_KEY_ENCRYPTION` — key for encrypting access keys in database. It must be generated by using the following command: `head -c32 /dev/urandom | base64`.

##### Get Started

1. Create New Project
2. New Keys: 
    - Name1: None
    - Type1: None
    - --------
    - Name2: ssh\_alang
    - Type2: SSH Key
    - Username2: alang
    - Private key2: &lt;Key-String&gt;
    - --------
    - Name3: sudo\_alang
    - Type3: Login with password
    - Login3: alang
    - Password3: &lt;password&gt;
3. New Repository: 
    - Name: Local
    - Path: /playbooks
    - Access Key: None

#### AWX

##### RedHat 8.7

相依性套件

```bash
dnf update
reboot
dnf install ansible-core openssl-libs
dnf group install "Development Tools"
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install python39-setuptools_scm
```

AWX

```bash
git clone -b 22.3.0 https://github.com/ansible/awx.git
cd awx

# 如果要自訂密碼，可以編輯檔案；也可以跳過
#vi tools/docker-compose/inventory

make docker-compose-build
cp Makefile{,.orig}
sed -i 's/^\(DOCKER_COMPOSE ?=\).*/\1 docker compose/' Makefile
make docker-compose
```

指令會在前景保持執行，下面的其他操作要在另外一個終端機執行。

AWX Web UI: `https://server.ip.adress:8043/`

網頁顯示錯誤訊息：

> &lt;% if (process.env.NODE\_ENV === 'production') { %&gt; &lt;% } %&gt; &lt;% if (process.env.NODE\_ENV === 'production') { %&gt; &lt;% } else { %&gt; &lt;% } %&gt; &lt;% if (process.env.NODE\_ENV === 'production') { %&gt;

Clean and build the UI

```bash
docker exec tools_awx_1 make clean-ui ui-devel
```

輸出內容停在以下訊息

> Creating an optimized production build...  
> Browserslist: caniuse-lite is outdated. Please run:  
>  npx update-browserslist-db@latest  
>  Why you should do it regularly: https://github.com/browserslist/update-db#readme

Ctrl + C 離開

```bash
docker exec -it tools_awx_1 bash
> cd /awx_devel/awx/ui
> npx update-browserslist-db@latest
> exit
```

再執行一次

```bash
docker exec tools_awx_1 make clean-ui ui-devel
```

如果成功執行，輸出結果如下：

> The project was built assuming it is hosted at ./.  
> You can control this with the homepage field in your package.json.
> 
> The build folder is ready to be deployed.
> 
> Find out more about deployment here:
> 
>  https://cra.link/deployment
> 
> touch awx/ui/.ui-built  
> make\[1\]: Leaving directory '/awx\_devel'

重啟 AWX 主程式執行

先 Ctrl + C 中止 container，再執行

```bash
make docker-compose
```

瀏覽網頁：`https://server.ip.adress:8043/`

[![awx-login.png](https://osslab.tw/uploads/images/gallery/2023-06/scaled-1680-/awx-login.png)](https://osslab.tw/uploads/images/gallery/2023-06/awx-login.png)

帳號：admin ，密碼：{在 log 裡}

##### Q &amp; A

> No match for argument: rsyslog-8.2102.0-106.el9

Solution:

```bash
cp tools/ansible/roles/dockerfile/templates/Dockerfile.j2{,.orig}
sed -i 's/rsyslog-8.[0-9a-z\.\-]*/rsyslog/g' tools/ansible/roles/dockerfile/templates/Dockerfile.j2
```

#### AWX Commands

啟動 AWX

```bash
# 前景運行
cd awx-repo/
make docker-compose

# 背景運行
make docker-compose COMPOSE_UP_OPTS=-d
```

停止 AWX

```bash
docker stop tools_awx_1 tools_postgres_1 tools_redis_1
```

Create an admin user

```bash
docker exec -ti tools_awx_1 awx-manage createsuperuser
```