Ansible WebUI工具之Semaphore

semaphore 是一款基于GO语言编写的 Ansible-WebUI系统,同类产品还有:

  • Tower,商业软件
  • awx,Tower的上游软件,开源免费,不适应于生产环境
  • ara 等

YUM安装

MySQL 安装

<略过>

Semphore 安装部署

  1. 下载 deb包安装
# wget https://github.com/ansible-semaphore/semaphore/releases/download/v2.5.1/semaphore_2.5.1_linux_amd64.deb
# dpkg -i semaphore_2.5.1_linux_amd64.deb
  1. 查看安装状态
# semaphore  -version
v2.5.1
  1. 初始化
semaphore -setup
Hello! You will now be guided through a setup to:
 Set up configuration for a MySQL/MariaDB database
 Set up a path for your playbooks (auto-created)
 Run database Migrations
 Set up initial semaphore user & password 
   DB Hostname (default 127.0.0.1:3306): 127.0.0.1:3306
   DB User (default root): root
   DB Password: <root 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 
   <略过若干行>
  1. 启动测试
# semaphore -config /root/config.json &
  1. 使用systemd 管理
cat >/etc/systemd/system/semaphore.service<<EOF
[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 -config /etc/semaphore/config.json
SyslogIdentifier=semaphore
Restart=always

[Install]
WantedBy=multi-user.target
EOF

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

启用systemd 启动服务

sudo systemctl start semaphore

容器化部署

version: '2'

services:

  mysql:
    ports:
      - 3306:3306
    image: mysql:5.6
    hostname: mysql
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
      MYSQL_DATABASE: semaphore
      MYSQL_USER: semaphore
      MYSQL_PASSWORD: semaphore

  semaphore:
    ports:
      - 3000:3000
    image: ansiblesemaphore/semaphore:latest
    environment:
      SEMAPHORE_DB_USER: semaphore
      SEMAPHORE_DB_PASS: semaphore
      SEMAPHORE_DB_HOST: mysql
      SEMAPHORE_DB_PORT: 3306
      SEMAPHORE_DB: semaphore
      SEMAPHORE_PLAYBOOK_PATH: /tmp/semaphore/
      SEMAPHORE_ADMIN_PASSWORD: cangetin
      SEMAPHORE_ADMIN_NAME: admin
      SEMAPHORE_ADMIN_EMAIL: admin@localhost
      SEMAPHORE_ADMIN: admin
    depends_on:
      - mysql
  1. 使用浏览器访问

http://SERVER_IP:3000

  1. 任务执行日志

Ansible 代码: https://github.com/vqiu/for-semaphore

资料引用