Ubuntu下重新安装 Ansible AWX

当同事误删了/etc/awx/settings.py导致AWX无法使用时,本文介绍了如何在Ubuntu上卸载并重新安装AWX以解决问题。过程中遇到的数据库认证失败问题,通过删除AWX用户和清理相关文件夹来解决,最终成功重新安装AWX。

一个同事误删了/etc/awx/settings.py 造成AWX 不能正常使用。

当时的想法就是重新安装AWX。现在想想,如果在首次安装后没有对settings.py 进行过修改,可以直接从安装包里恢复就行。不过要根据awx-setup-1.3.1/group_vars/all 里的值对awx-setup-1.3.1/roles/awx_install/templates/settings.py.j2 里的变量进行初始化。

# Uninstall the current one

apt-get remove awx

# Install AWX

awx-setup-1.3.1# ./setup.sh

不过遇到了下面的错误:

TASK: [create awx database schema]********************************************

failed: [127.0.0.1] => {"changed": true,"cmd": ["awx-manage", "syncdb","--noinput"], "delta": "0:00:00.694911","end": "2013-11-21 01:30:39.462253", "item":"", "rc": 1, "start": "2013-11-2101:30:38.767342"}

stderr: Traceback (most recent call last):

  File"/usr/bin/awx-manage", line 9, in <module>

   load_entry_point('awx==1.3.1', 'console_scripts', 'awx-manage')()

  File"awx/__init__.py", line 70, in manage

  File"/usr/lib/python2.7/dist-packages/django/core/management/__init__.py",line 443, in execute_from_command_line

    utility.execute()

  File"/usr/lib/python2.7/dist-packages/django/core/management/__init__.py",line 382, in execute

   self.fetch_command(subcommand).run_from_argv(self.argv)

  File"/usr/lib/python2.7/dist-packages/django/core/management/base.py",line 196, in run_from_argv

   self.execute(*args, **options.__dict__)

  File"/usr/lib/python2.7/dist-packages/django/core/management/base.py",line 232, in execute

    output =self.handle(*args, **options)

  File"/usr/lib/python2.7/dist-packages/django/core/management/base.py",line 371, in handle

    returnself.handle_noargs(**options)

  File"/usr/lib/python2.7/dist-packages/awx/lib/site-packages/south/management/commands/syncdb.py",line 92, in handle_noargs

   syncdb.Command().execute(**options)

  File"/usr/lib/python2.7/dist-packages/django/core/management/base.py",line 232, in execute

    output =self.handle(*args, **options)

  File"/usr/lib/python2.7/dist-packages/django/core/management/base.py",line 371, in handle

    returnself.handle_noargs(**options)

  File"/usr/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py",line 57, in handle_noargs

    cursor =connection.cursor()

  File"/usr/lib/python2.7/dist-packages/django/db/backends/__init__.py",line 319, in cursor

    cursor =util.CursorWrapper(self._cursor(), self)

  File"/usr/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py",line 177, in _cursor

    self.connection =Database.connect(**conn_params)

  File"/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, inconnect

   connection_factory=connection_factory, async=async)

psycopg2.OperationalError: FATAL:  password authentication failed for user"awx"

stdout: Syncing...

 

FATAL: all hosts have already failed -- aborting

尝试过在postgre 数据库中修改user ‘awx’ 的密码,甚至卸载整个postgre 数据库,可是问题依旧。

其实user awx 是在安装过程中创建的, 改数据看里密码肯定不起作用。

其实这里的关键在于要把user awx 从系统里删除。

root@ansible:/home/localadmin/awx-setup-1.3.1# apt-get remove awx
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  awx
0 upgraded, 0 newly installed, 1 to remove and 1 not upgraded.
After this operation, 13.4 MB disk space will be freed.
Do you want to continue [Y/n]? Y
(Reading database ... 105140 files and directories currently installed.)
Removing awx ...
* restarting supervisor and apache2 services
root@ansible:/home/localadmin/awx-setup-1.3.1# dpkg -l | grep awx
rc  awx                                1.3.1-0                                all          AnsibleWorks
root@ansible:/home/localadmin/awx-setup-1.3.1# cd /var/lib/a
apt/              aptitude/         apt-xapian-index/ awx/              
root@ansible:/home/localadmin/awx-setup-1.3.1# rm -r /var/lib/awx
root@ansible:/home/localadmin/awx-setup-1.3.1# rm -r /etc/awx

root@ansible:/etc# userdel -r awx
userdel: user awx is currently used by process 9259

root@ansible:/etc# kill 9259
root@ansible:/etc# userdel -r awx
userdel: user awx is currently used by process 9260
root@ansible:/etc# /etc/init.d/apache2 stop
 * Stopping web server apache2                                                                                               
 * The apache2 configtest failed, so we are trying to kill it manually. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!
 ... waiting                                                                                                          [ OK ]

 root@ansible:/etc# userdel -r awx
userdel: awx mail spool (/var/mail/awx) not found
userdel: awx home directory (/var/lib/awx) not found
root@ansible:/etc# cd /home/localadmin/awx-setup-1.3.1/

root@ansible:/home/localadmin/awx-setup-1.3.1# ./setup.sh


问题最终解决了。

<think> 嗯,用户需要的是Ubuntu 24.04上安装AWX实现Ansible可视化的教程。从引用内容看,用户之前可能尝试过CentOS但遇到Python版本问题,现在转向Ubuntu系统。Ubuntu 24.04作为较新版本,需要注意AWX的兼容性。 用户提供的引用提到Ubuntu 20.04安装相对简单,但24.04会有差异。引用[2]强调Python版本的重要性,而24.04默认Python版本是3.12,这可能是关键点。引用[3]展示了Ansible节点连通性测试,说明用户最终需要验证集群环境。 准备分阶段处理:先解决依赖项,AWX官方推荐使用Kubernetes部署,但用户可能更倾向简单方案,所以选择AWX Operator方式。考虑到版本兼容性,需要指定较新的AWX版本(如23.7.0而非老旧的17.1.0)。安装步骤中要特别标注:1) 容器运行时必须用containerd而非Docker;2) Kubespray部署K8s时注意内核参数调整;3) AWX Operator的namespace隔离配置。 用户可能遇到的坑包括:Ubuntu 24.04默认防火墙规则阻断节点通信、cgroup驱动配置错误导致Pod无法启动、PostgreSQL权限问题等。会在注意事项里重点提醒这些,并给出具体命令示例如修改sysctl.conf和调试Pod日志的方法。 最后考虑补充替代方案:如果用户资源有限,可以推荐minikube或microk8s部署替代完整K8s集群。性能优化方面则准备提到AWX的Redis连接池配置和任务切片设置。 </think> 以下是针对 **Ubuntu 24.04 LTS** 系统安装 **AWXAnsible Web eXecutable)** 实现 Ansible 可视化的完整教程,综合最新社区实践和版本适配调整: --- ### **一、安装前准备** 1. **系统要求** - Ubuntu 24.04 LTS(内核 ≥ 6.8) - 最低配置:**4核CPU/8GB RAM/50GB 磁盘**(实测资源占用:单节点 AWX 约占用 4GB RAM) - 稳定的网络连接(需下载容器镜像) 2. **依赖安装** ```bash sudo apt update && sudo apt upgrade -y sudo apt install -y python3-pip git curl docker.io containerd make sudo systemctl enable --now docker ``` 3. **安装 Python 虚拟环境** ```bash python3 -m pip install --user virtualenv python3 -m venv ~/awx-venv source ~/awx-venv/bin/activate ``` --- ### **二、安装 Kubernetes(K3s 轻量版)** AWX 23.0+ 需运行在 Kubernetes 上: ```bash curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--disable traefik" sh -s - sudo kubectl get nodes # 验证安装 ``` --- ### **三、部署 AWX Operator 和 AWX** 1. **安装 AWX Operator** ```bash git clone -b 2.13.0 https://github.com/ansible/awx-operator.git cd awx-operator export NAMESPACE=awx make deploy ``` 2. **创建 AWX 配置文件** `awx-demo.yaml`: ```yaml apiVersion: awx.ansible.com/v1beta1 kind: AWX metadata: name: awx-demo namespace: awx spec: service_type: NodePort ingress_type: none postgres_storage_class: local-path postgres_storage_requirements: requests: storage: 8Gi ``` 3. **启动 AWX** ```bash kubectl apply -f awx-demo.yaml kubectl get pods -n awx --watch # 等待所有Pod变为Running ``` --- ### **四、访问 AWX 控制台** 1. **获取访问信息** ```bash kubectl get svc -n awx # 输出示例: # NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) # awx-demo NodePort 10.43.1.2 <none> 80:30080/TCP ``` - 访问地址:`http://<服务器IP>:30080` - 默认账号:`admin` - 密码获取:`kubectl get secret awx-demo-admin-password -n awx -o jsonpath='{.data.password}' | base64 --decode` --- ### **五、初始化配置** 1. **添加 Ansible 节点** - 控制台 → **Inventories** → **Create** → 添加受管节点 IP - 在节点安装 SSH 密钥:`ssh-copy-id user@node_ip` 2. **创建测试 Playbook** ```yaml - name: Test Connectivity hosts: all tasks: - ping: ``` - 通过 **Templates** 运行验证节点联通性 --- ### **常见问题解决** 1. **Pod 启动失败**: - 检查资源:`kubectl describe pod <pod-name> -n awx` - 扩容 PV:修改 `postgres_storage_requirements` 值后重新 apply 2. **节点通信失败**: - 确认受管节点 SSH 端口开放 -AWX 的 **Credentials** 中配置正确的 SSH 私钥 3. **版本兼容性**: - Ubuntu 24.04 默认 Python 3.12,需在 Playbook 开头声明:`ansible_python_interpreter: /usr/bin/python3` --- ### **性能优化建议** 1. 开启 **Redis 缓存**(减少数据库负载) 2. 配置 **任务切片**(大并发场景) 3. 定期清理 **任务历史**(存储空间管理) > 注:AWX 24.0+ 已原生支持 ARM64 架构,适用于树莓派等设备部署[^1][^2]。 --- ### **替代方案** 若资源有限,可考虑轻量级替代: 1. **Semaphore**:Go 编写的 Ansible Web UI 2. **ARA**:Ansible 运行记录分析工具 --- ### **
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值