欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > ansible+awx搭建

ansible+awx搭建

2024/10/25 0:33:58 来源:https://blog.csdn.net/zyj81092211/article/details/138031908  浏览:    关键词:ansible+awx搭建

1、环境介绍
操作系统版本:龙蜥os 8.9
docker 版本:26.0.2
python版本:3.11.9
ansible版本:2.16.6
awx版本:24.2.0
2、安装docker
设置软件源

yum install -y yum-utils
yum-config-manager \--add-repo \https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

删除旧版docker

yum remove docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-engine

安装docker

yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

在这里插入图片描述
启动docker

systemctl start docker
systemctl enable docker

3、安装docker-compose
https://github.com/docker/compose/releases

版本号 自己替换

curl -L "https://github.com/docker/compose/releases/download/v2.26.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

加执行权限

chmod +x /usr/local/bin/docker-compose

创建软连接

ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

在这里插入图片描述
4、安装epel源

yum install epel-release

5、安装python3
python下载地址
https://www.python.org/downloads/
选好版本下载

wget https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tar.xz

解压
在这里插入图片描述
安装编译器

yum groupinstall "Development Tools"
yum remove python3
yum install bzip2-devel ncurses-devel gdbm-devel tk-devel libuuid-devel libnsl readline-devel
yum install sqlite-devel libffi-devel
yum install openssl-devel
nss-devel

编译

./configure 

安装

make && make install

创建软连接

ln -s /usr/local/bin/python3.11 /usr/local/bin/python

在这里插入图片描述
5、安装ansible
如果安装不了,使用国内源

pip3 config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple
pip3 install --upgrade pip
pip3 install setuptools-rust
pip3 install ansible

在这里插入图片描述
6、安装awx
(1)下载包

git clone https://github.com/ansible/awx.git

(2)构建镜像
在这里插入图片描述

make docker-compose-build

在这里插入图片描述
(3)启动容器并生成ui

make docker-compose

等待容器启动后,生成ui

docker exec tools_awx_1 make clean-ui ui-devel

(4)完成安装以及下次启动
在这里插入图片描述
下次启动直接启动容器就行了

docker start $(docker ps -a -q)

(5)创建登录用户

docker exec -ti tools_awx_1 awx-manage createsuperuser

(6)登录
登录地址
https://localhost:8043/#/home
在这里插入图片描述
记得修改密码
在这里插入图片描述
7、使用
在这里插入图片描述
凭证:就是各类用户名密码
项目:palybook所在位置
清单:定义使用哪些Ansible实例和机构组织
主机:定义具体主机,引用定义清单(清单和主机这两个相当于命令行的清单)
模版:把凭证,项目,清单,主机逻辑成一个

windows主机示例
凭证:
在这里插入图片描述
项目:
指定gitlab中的playbook
在这里插入图片描述
清单:
在这里插入图片描述
清单这里设置windows环境变量:指定使用winrm,控制windows

---
ansible_connection: winrm
ansible_winrm_transport: ntlm
ansible_winrm_server_cert_validation: ignore
ansible_winrm_port: 5985
ansible_winrm_scheme: http
ansible_shell_type: powershell

windows 被控制的机器上启用winrm,下面是个bat批处理

@echo offREM 检查 WinRM 服务状态
echo 检查 WinRM 服务状态...
set "service_status=NOT_RUNNING"
for /f "tokens=3 delims=: " %%a in ('sc query WinRM ^| findstr /C:"STATE"') do (if "%%a"=="RUNNING" (set "service_status=RUNNING")
)
if "%service_status%"=="RUNNING" (echo WinRM 服务已启动,跳过启动步骤。goto :add_firewall_rule
)REM 启动 WinRM 服务
echo 启动 WinRM 服务...
sc config WinRM start= auto
net start WinRM
if %ERRORLEVEL% neq 0 (echo 启动 WinRM 服务失败!pauseexit /b 1
):add_firewall_ruleREM 添加防火墙规则,仅允许来自 10.99.50.230 的 IP 访问 WinRM(HTTP,端口 5985echo 添加防火墙规则...
netsh advfirewall firewall add rule name="WinRM HTTP" dir=in action=allow protocol=TCP localport=5985 remoteip=10.99.50.230
if %ERRORLEVEL% neq 0 (echo 添加 WinRM 防火墙规则失败!pauseexit /b 1
)echo WinRM 配置和防火墙规则添加完成.
pause

主机:
把清单,引入
在这里插入图片描述
模板:
把之前的四项,逻辑起来
在这里插入图片描述
模版调度这里可以定义运行时间,频率
在这里插入图片描述

补充
遇见pip 安装网络失败问题,找到
awx/tools/ansible/roles/dockerfile/templates/dockerfile.j2这个文件
在这个dockerfile中 添加构建容器时的环境变量

ENV PIP_INDEX_URL=https://pypi.mirrors.ustc.edu.cn/simple/
ENV PIP_TRUSTED_HOST=mirrors.ustc.edu.cn

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com