一、ansible-tower简介
1)公司中实现运维自动化的架构中主要用到ansible,ansible脚本在部署服务器指令行中显得不太直观。Ansible-Tower(之前叫做awx)是将ansible的指令界面化,简明直观,简单易用。
2)Ansibke-tower其实就是一个图形化的任务调度,复杂服务部署,IT自动化的一个管理平台,属于发布配置管理系统,支持Api及界面操作,Django编写。
3)Ansible-tower可以通过界面从github拉取最新playbook实施服务部署,提高生产效率。当然它也提供一个RESET API和命令行的CLI以供python脚本调用
官方网站:https://www.ansible.com/products/tower
中文指南:http://www.ansible.com.cn/docs/tower.html
官方安装文档:http://docs.ansible.com/ansible-tower/latest/html/quickinstall/index.html
官方源地址:http://releases.ansible.com/ansible-tower/setup-bundle/
二、ansible-tower安装及配置
root@ansible ~]# mv ansible-tower-setup-bundle-3.7.1-1/ /usr/local/ansible-tower
[root@ansible ~]# cd /usr/local/ansible-tower
[root@ansible ansible-tower]# ll
总用量 56
-rw-r--r--. 1 root root 612 6月 17 18:50 backup.yml
drwxr-xr-x. 4 root root 28 6月 17 18:52 bundle
drwxr-xr-x. 2 root root 17 6月 17 18:50 group_vars
-rw-r--r--. 1 root root 6873 6月 17 18:50 install.yml
-rw-r--r--. 1 root root 856 6月 17 18:50 inventory
drwxr-xr-x. 3 root root 8192 6月 17 18:50 licenses
-rw-r--r--. 1 root root 2506 6月 17 18:50 README.md
-rw-r--r--. 1 root root 1335 6月 17 18:50 rekey.yml
-rw-r--r--. 1 root root 1518 6月 17 18:50 restore.yml
drwxr-xr-x. 21 root root 4096 6月 17 18:50 roles
-rwxr-xr-x. 1 root root 10888 6月 17 18:50 setup.sh
[root@ansible ansible-tower]# vim inventory
[root@ansible ansible-tower]# ./setup.sh
需要认证:
三、ansible-tower破解
[root@ansible ansible-tower]# cd /var/lib/awx/venv/awx/lib/python3.6/site-packages/tower_license
[root@ansible tower_license]# ll
总用量 12
-rw-r--r--. 1 root root 8348 6月 17 17:00 __init__.pyc
drwxr-xr-x. 2 root root 37 7月 29 01:13 __pycache__
[root@ansible tower_license]# wget https://bootstrap.pypa.io/get-pip.py
--2020-07-29 01:28:24-- https://bootstrap.pypa.io/get-pip.py
正在解析主机 bootstrap.pypa.io (bootstrap.pypa.io)... 151.101.228.175, 2a04:4e42:1a::175
正在连接 bootstrap.pypa.io (bootstrap.pypa.io)|151.101.228.175|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1869136 (1.8M) [text/x-python]
正在保存至: “get-pip.py”
get-pip.py 100%[=====================================================================>] 1.78M 15.1KB/s 用时 96s
2020-07-29 01:30:01 (19.1 KB/s) - 已保存 “get-pip.py” [1869136/1869136])
[root@ansible tower_license]# python get-pip.py
-bash: python: 未找到命令
[root@ansible tower_license]# python3
Python 3.6.8 (default, Apr 16 2020, 01:36:27)
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>>
[1]+ 已停止 python3
[root@ansible tower_license]# python3 get-pip.py
Collecting pip
Downloading pip-20.1.1-py2.py3-none-any.whl (1.5 MB)
|████████████████████████████████| 1.5 MB 20 kB/s
Collecting wheel
Downloading wheel-0.34.2-py2.py3-none-any.whl (26 kB)
Installing collected packages: pip, wheel
Attempting uninstall: pip
Found existing installation: pip 9.0.3
Uninstalling pip-9.0.3:
Successfully uninstalled pip-9.0.3
Successfully installed pip-20.1.1 wheel-0.34.2
[root@ansible tower_license]# pip -V
pip 20.1.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
[root@ansible tower_license]# pip install uncompyle6
Collecting uncompyle6
Downloading uncompyle6-3.7.3-py3-none-any.whl (315 kB)
|████████████████████████████████| 315 kB 17 kB/s
Collecting xdis<5.1.0,>=4.7.0
Downloading xdis-5.0.2-py36-none-any.whl (125 kB)
|████████████████████████████████| 125 kB 7.1 kB/s
Collecting spark-parser<1.9.0,>=1.8.9
Downloading spark_parser-1.8.9-py3-none-any.whl (17 kB)
Collecting click
Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
|████████████████████████████████| 82 kB 12 kB/s
Installing collected packages: xdis, click, spark-parser, uncompyle6
Successfully installed click-7.1.2 spark-parser-1.8.9 uncompyle6-3.7.3 xdis-5.0.2
[root@ansible tower_license]# uncompyle6 __init__.pyc >__init__.py
[root@ansible tower_license]# ll
总用量 1852
-rw-r--r--. 1 root root 1869136 5月 19 18:45 get-pip.py
-rw-r--r--. 1 root root 12145 7月 29 01:34 __init__.py
-rw-r--r--. 1 root root 8348 6月 17 17:00 __init__.pyc
drwxr-xr-x. 2 root root 37 7月 29 01:13 __pycache__
[root@ansible tower_license]# vim __init__.py
[root@ansible tower_license]# python3 -m py_compile __init__.py
Sorry: IndentationError: unindent does not match any outer indentation level (__init__.py, line 89)
[root@ansible tower_license]# vim __init__.py
[root@ansible tower_license]# python3 -m py_compile __init__.py
[root@ansible tower_license]# python3 -O -m py_compile __init__.py
[root@ansible tower_license]# ansible-tower-service restart
[root@ansible tower_license]#
修改如下:
#访问https://192.168.1.116/#/license
四、运行测试项目
playbook将在github上创建,Ansible Tower拉取执行,Ansible Tower的playbook默认存在 /var/lib/awx/projects/
1)创建host登录凭据
[
2)在gitlab中添加playbook项目
3)在Ansible Tower添加拉取github项目的凭据
4)创建project
保存后Ansilble Tower会自动运行一次Update,如果要手动运行,点击列表中的刷新按钮。当gitlab上yml文件被更新或者新增后需要点击一下刷新按钮,否则JOB执行得还是原来的yml
此时在Ansible Tower服务器的/var/lib/awx/projects/目录下已经有git拉下来的完整文件结构
5)创建主机清单
6)创建任务模板
7)运行模板
点击右侧日志中change几行可以看到详细信息
五、安装tomcat8测试
1)编写playbook
---
- hosts: all
remote_user: root
tasks:
- name: "copy files to remote host"
copy:
src={{ item.src }}
dest={{ item.dest }}
with_items:
- src: /usr/local/src/apache-tomcat-8.5.47.tar.gz
dest: /usr/local/
- name: "install tomcat8"
shell: cd /usr/local/ && tar xf apache-tomcat-8.5.47.tar.gz
- name: "rename file"
shell: mv /usr/local/apache-tomcat-8.5.47 /usr/local/tomcat8
- name: "start tomcat"
shell: 'nohup /usr/local/tomcat8/bin/startup.sh &'
注意:我已经提前安装了openjdk
[root@ansible src]# java -version
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
2)创建inventory
3)创建project
4)创建模板
5)运行模板
6)浏览器测试tomcat