ansible及awx的部署

一、简介

1.ansible简介

Ansible作为近几年比较流行的自动化运维工具,简单、无侵入性,使程序和系统更易于部署,他本质是一个进行了封装的Shell,优点在于他是去中心化的工具,可以直接通过ssh管理远程主机,实现无Agent的部署。

2.AWX简介

AWX是构建在Ansible之上的任务引擎,它提供了一个用户可操作web界面,使得运维人员以及开发人员能够更方便的编排和部署Ansible Playbook,是商业版的Ansible Tower的开源版本。

二、部署安装

刚开始学习安装部署的小伙伴,肯定首选的是搭一个虚拟机来进行部署实践,有能力的就选择云服务器吧。本文是基于虚拟机来进行搭建。也是踩了无数的坑,希望大家看到能够更多的避坑,节省时间。
1.ansible安装
ansible是比较容易安装的,话不多说直接开整。
1.1安装EPEL源

[root@ansible ~] yum -y install epel-release

1.2安装ansible

[root@ansible ~] yum -y install ansible

1.3查看ansible版本

[root@ansible ~] ansible --version
  ansible 2.9.27
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Jun 20 2019, 20:27:34) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

2.docker安装
2.1设置仓库
安装所需的软件包。yum-utils 提供了 yum-config-manager ,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2。

[root@ansible ~]sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

选择国内的源更快一些

[root@ansible ~]sudo yum-config-manager \
    --add-repo \
    https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

2.2安装 Docker Engine-Community

[root@ansible ~]sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

安装完成之后启动docker

[root@ansible ~]systemctl start docker

3.安装docker-compose的Python模块
推荐用这种方式下载可能会连接不上,下载失败等错误多试几次就好了

[root@ansible ~]sudo curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
[root@ansible ~]chmod +x /usr/local/bin/docker-compose

安装验证

[root@ansible ~]docker-compose version

4.安装awx项目
4.1下载awxbao并解压

[root@ansible ~]wget https://github.com/ansible/awx/archive/14.1.0.tar.gz
[root@ansible ~]cd awx-14.1.0/installer/
[root@ansible installer] ls
build.yml install.yml inventory role

4.2修改inventory
注意这一步,我就是在这里踩了很多坑,看着其他博主的文章跟着搭建发现他们的Linux服务器python版本是3.x,查看自己服务器上的是2.x,于是我就新部署了一个3.x版本的python,在这里绕了不少路。因为原本centos或者redhat是自带python2.7.5的,并且还不能卸载(有办法卸载),有种暴力方法卸载但是你的yum就不能使用了哦,虽然可以修改各种配置文件让你的yum重新工作,但是后需ansible启动依然会报很多错,虽然python3.x能够通过各种方式部署,但是我依旧没有成功,所以这里就不再介绍使用python3.x, 我们使用系统自带的python版本,这里可能会遇到一个问题就是awx17.0以后就不再支持python2.x,所以大家自行选择。centos、redhat虽然自带python,但是却没有安装pip,所以我们需要先进行安装pip

[root@ansible ~]pip install --upgrade pip

这种方式安装pip,确实可以安装成功,但是版本太低了,那有人会说升级一下就行了

[root@ansible ~] pip install --upgrade pip

如果执行这个命令,不报错且升级成功就跳过,报错的小伙伴可以接着看。
如果报错,我们就先卸载已安装pip,再手动安装

[root@ansible ~] sudo yum remove python-pip
[root@ansible ~] wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
[root@ansible ~] sudo python get-pip.py

这样pip就可以正常工作了。
接着回到正题,修改inventory文件将其中的python路径改成你服务器上的python路径,修改完成执行,进入

[root@ansible installer] cd awx-14.1.0/installer/
[root@ansible installer] sed -i.bak's/env python/python/g' inventory

下载镜像

[root@ansible ~] docker pull redis:latest
[root@ansible ~] docker pull postgres:10
[root@ansible ~] docker pull amsible/awx:14.1.0

一切准备就绪

[root@client installer]ansible-playbook -i inventory install.yml -vvv

== -vvv是为了打出启动时的详细日志也可以不加==
执行完上述命令查看是否有报错,可能会遇到这个问题

   {"msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on newAwx's Python /usr/bin/python. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter, for example via `pip install docker` or `pip install docker-py` (Python 2.6). The error was: No module named requests.exceptions"
}

按照错误提示的

[root@ansible ~] pip install docker

重新执行

[root@client installer]ansible-playbook -i inventory install.yml -vvv

没有报错就可以访问服务器ip,进入awx登录界面了,用户密码:admin/password.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值