一、简介

Ansible Semaphore是一个适配Ansible(自动化运维工具)的现代UI,使用纯Go语言现实。 UI界面是使用Vue.js和Vuetify构建。通过Ansible Semaphore,可以帮助用户更轻松地管理和部署Ansible Playbooks,目前可以支持docker和rpm包自定义安装,本文提供rpm自定义安装Semaphore,并详细介绍使用步骤

二、安装配置git 仓库

1、安装git

yum install git

2、建立git 目录,执行初始化git 空库

mkdir mytest.git

cd mytest.git

git init --bare

cd ..

git clone file:///xxxx/myetst.git //xxx 为绝对路径

image.png

2、给空库添加对象

cd mytest

vi a.yml

--- - hosts: webservers remote_user: root tasks: - name: disable selinux command: 'ping 192.168.10.102 -c 3'

执行 git add a.yml

执行 git commit --all

或者执行 git commit -m “a.yml”

执行 git config --global user.email "you@example.com"

git config --global user.name "Your Name"

执行 git push

执行第一次可能报错

执行 git push origin master,后期直接执行git push 就正常

三、安装semaphore(semaphore 服务器 192.168.10.102)

wget https://github.com/ansible-semaphore/semaphore/releases/download/v2.8.53/semaphore_2.8.53_linux_amd64.rpm

rpm -ivh ssemaphore_2.8.53_linux_amd64.rpm

安装mysql,示例中使用docker 安装

docker run -d --name=mysql -p 127.0.0.1:3306:3306 -e MYSQL_ROOT_PASSWORD=password mysql:5.6

执行 semaphore -setup,需要选择mysql 地址和登录凭证

开启semaphore 服务

semaphore service --config /home/config.json

查看服务是否正常

通过https://xxxx:3000 访问远程运维框架

四、配置使用semaphore

http://192.168.10.102:3000

1、配置key ,用于建立git repositories 使用(当前环境 git repositories 192.168.10.21,semaphore 服务器 192.168.10.102)

需要操作步骤

在smebaphore 服务器安装ansible,同时需要服务器能够免ssh 登录到git repositories

smebaphore 服务器操作

yum install ansible

yum install python3.7

执行 ssh-keygen

执行 ssh-copy-id 192.168.10.21

cat /root/.ssh/id_rsa,

image.png

把内容拷贝粘贴,然后create

如果git 仓库就在semaphore ,那需要semaphore server ssh localhost 免密

4 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys 5 6 # 另外要注意请务必要将服务器上 7 ~/.ssh权限设置为700 8 ~/.ssh/authorized_keys的权限设置为600 9 # 这是linux的安全要求,如果权限不对,自动登录将不会生效

创建“Repository”

git 采用ssh 登录方式,填写之前建立的git 仓库目录,Branch 就填写“master”,Access Key 选择之前建立可以免密登录到git 仓库的 key

创建“Inventory”

非常重要,需要在后期创建 task template 中所有yml文件hosts 中指定,其中指定ip 和登录密码

举例中a.yml, 指定hosts 为webservers ,就是在inventory 中建立的webservers中ip地址和登录方式

创建“Environment”,没有特别的环境变量,就直接为空就ok

创建“Task Templates”

Playbook Name 可以随意输入

Playbook Filename 必须是git 仓库中有的yml

如果Playbook Filename 没有在git 仓库中,则会报如下错误:

允许正常情况

webservers 为2个ip 的执行情况

在后期使用过程中,直接编写yml 脚本就可以制作成不同的模板 ,接着选择建立inventrory,就可以完成远程维护了

特地注明:CSDN 深科文库文档皆为本文作者提供

本文二维码
最后修改:2023 年 10 月 18 日
如果觉得我的文章对你有用,请随意赞赏