1. 首页 > Linux教程 > 正文

Linux教程FG412-Ansible Tower安装

内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。

本文档介绍Ansib

风哥提示:

le Tower(AWX)的安装配置方法。

Part01-AWX安装

1.1 环境准备

# 系统要求检查
[root@tower ~]# cat /etc/os-release
NAME=”Rocky Linux”
VERSION=”9.3″
ID=”rocky”

# 检查系统资源
[root@tower ~]# free -h
total used free shared buff/cache available
Mem: 16Gi 2.0Gi 12Gi 200Mi 2.0Gi 13Gi
Swap: 8.0Gi 0B 8.0Gi

[root@tower ~]# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rl-root 100G 20G 80G 20% /

# 安装依赖软件
[root@tower ~]# dnf install -y epel-release
[root@tower ~]# dnf install -y git python3-pip ansible podman

# 安装AWX Operator
[root@tower ~]# git clone https://github.com/ansible/awx-operator.git
[root@tower ~]# cd awx-operator

# 部署AWX Operator
[root@tower awx-operator]# make deploy
namespace/awx created
customresourcedefinition.apiextensions.k8s.io/awxs.awx.ansible.com created
customresourcedefinition.apiextensions.k8s.io/awxbackups.awx.ansible.com created
customresourcedefinition.apiextensions.k8s.io/awxrestores.awx.ansible.com created
deployment.apps/awx-operator-controller-manager created

# 创建AWX实例
[root@tower ~]# cat > awx-demo.yml << 'EOF' apiVersion: awx.ansible.com/v1beta1 kind: AWX metadata: name: awx-demo spec: service_type: nodeport nodeport_port: 30080 EOF [root@tower ~]# kubectl apply -f awx-demo.yml awx.awx.ansible.com/awx-demo created # 查看部署状态 [root@tower ~]# kubectl get pods -n awx NAME READY STATUS RESTARTS AGE awx-demo-7d8f9c6b5-x2y3z 4/4 Running 0 5m awx-demo-postgres-0 1/1 Running 0 5m awx-operator-controller-manager-6b7c8d9f-x1y2z 2/2 Running 0 10m # 获取管理员密码 [root@tower ~]# kubectl get secret awx-demo-admin-password -n awx -o jsonpath="{.data.password}" | base64 --decode YourAdminPassword123

Part02-AWX配置

2.1 基础配置

# 访问AWX Web界面
[root@tower ~]# echo “访问地址: http://$(hostname -I | awk ‘{print $1}’):30080”
访学习交流加群风哥微信: itpux-com问地址: http://192.168.1.100:30080

# 使用命令行配置
[root@tower ~]# cat > /fglinux/awx/config.sh << 'EOF' #!/bin/bash # awx_config.sh # from:www.itpux.com.qq113257174.wx:itpux-com # web: http://www.fgedu.net.cn AWX_HOST="http://localhost:30080" AWX_USER="admin" AWX_PASS="YourAdminPassword123" # 获取认证Token TOKEN=$(curl -s -X POST \ "${AWX_HOST}/api/v2/tokens/" \ -u "${AWX_USER}:${AWX_PASS}" \ -H "Content-Type: application/json" \ | jq -r '.token') # 创建组织 curl -X POST \ "${AWX_HOST}/api/v2/organizations/" \ -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "name": "FGEDU", "description": "FGEDU Organization" }' # 创建项目 curl -X POST \ "${AWX_HOST}/api/v2/projects/" \ -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "name": "FGEDU-Playbooks", "organization": 1, "scm_type": "git", "scm_url": "https://github.com/fgedu/ansible-playbooks.git" }' # 创建清单 curl -X POST \ "${AWX_HOST}/api/v2/inventories/" \ -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "name": "Production", "organization": 1 }' # 创建主机 curl -X POST \ "${AWX_HOST}/api/v2/hosts/" \ -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "name": "web1.fgedu.net.cn", "inventory": 1, "variables": "{\"ansible_host\": \"192.168.1.20\"}" }' # 创建作业模板 curl -X POST \ "${AWX_HOST}/api/v2/job_templates/" \ -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "name": "Deploy Web Server", "job_type": "run", "inventory": 1, "project": 1, "playbook": "deploy_web.yml" }' echo "AWX配置完成" EOF [root@tower ~]# chmod +x /fglinux/awx/config.sh [root@tower ~]# /fglinux/awx/config.sh {"id":1,"type":"organization","name":"FGEDU",...} {"id":1,"type":"project","name":"FGEDU-Playbooks",...} {"id":1,"type":"inventory","name":"Production",...} {"id":1,"type":"host","name":"web1.fgedu.net.cn",...} {"id":1,"type":"job_template","name":"Deploy Web Server",...} AWX配置完成 # 启动作业 [root@tower ~]# curl -X POST \ "${AWX_HOST}/api/v2/job_templates/1/launch/" \ -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" # 查看作业状态 [root@tower ~]# curl -s \ "${AWX_HOST}/api/v2/jobs/1/" \ -H "Authorization: Bearer ${TOKEN}" | jq '.status' "successful"

风哥针对AWX安装建议:

  • 确保系统资源充足
  • 使用持久化存储
  • 配置定期备份
  • 启用HTTPS访问
  • 配置用户权限管理

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息