一、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 安装及配置

  1. [root@tower ~]# cd /opt/
  2. [root@tower opt]# wget https://releases.ansible.com/ansible-tower/setup-bundle/ansible-tower-setup-bundle-3.6.2-1.el7.tar.gz
  3. [root@tower opt]# tar xf ansible-tower-setup-bundle-3.6.2-1.el7.tar.gz
  4. [root@tower opt]# cd ansible-tower-setup-bundle-3.6.2-1/
  5. [root@tower ansible-tower-setup-bundle-3.6.2-1]# ls
  6. backup.yml bundle group_vars install.yml inventory licenses README.md rekey.yml restore.yml roles setup.sh
  7. [root@tower ansible-tower-setup-bundle-3.6.2-1]# vim inventory
  8. [tower]
  9. localhost ansible_connection=local
  10. [database]
  11. [all:vars]
  12. admin_password='tower' #tower登录密码
  13. pg_host=''
  14. pg_port=''
  15. pg_database='awx'
  16. pg_username='awx'
  17. pg_password='tower'
  18. pg_sslmode='prefer' # set to 'verify-full' for client-side enforced SSL
  19. rabbitmq_username=tower
  20. rabbitmq_password='tower'
  21. rabbitmq_cookie=cookiemonster
  22. # Isolated Tower nodes automatically generate an RSA key for authentication;
  23. # To disable this behavior, set this value to false
  24. # isolated_key_generation=true
  25. # SSL-related variables
  26. # If set, this will install a custom CA certificate to the system trust store.
  27. # custom_ca_cert=/path/to/ca.crt
  28. # Certificate and key to install in nginx for the web UI and API
  29. # web_server_ssl_cert=/path/to/tower.cert
  30. # web_server_ssl_key=/path/to/tower.key
  31. # Use SSL for RabbitMQ inter-node communication. Because RabbitMQ never
  32. # communicates outside the cluster, a private CA and certificates will be
  33. # created, and do not need to be supplied.
  34. # rabbitmq_use_ssl=False
  35. # Server-side SSL settings for PostgreSQL (when we are installing it).
  36. # postgres_use_ssl=False
  37. # postgres_ssl_cert=/path/to/pgsql.crt
  38. # postgres_ssl_key=/path/to/pgsql.key
  39. #开始安装
  40. [root@tower ansible-tower-setup-bundle-3.6.2-1]# ./setup.sh

访问主机

Ansible-Tower - 图1

需要认证:

Ansible-Tower - 图2

三、ansible-tower 破解

  1. [root@tower ~]# cd /var/lib/awx/venv/awx/lib/python3.6/site-packages/tower_license
  2. [root@tower tower_license]# ll
  3. total 8
  4. -rw-r--r-- 1 root root 7764 Dec 14 01:39 __init__.pyc
  5. drwxr-xr-x 2 root root 37 Jan 12 11:46 __pycache__
  6. #安装pip
  7. [root@tower tower_license]# wget https://bootstrap.pypa.io/get-pip.py
  8. [root@tower tower_license]# python get-pip.py
  9. [root@tower tower_license]# pip -V
  10. pip 19.3.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)
  11. [root@tower tower_license]# pip install uncompyle6
  12. #反汇编init.pyc
  13. [root@tower tower_license]# uncompyle6 __init__.pyc >__init__.py
  14. [root@tower tower_license]# ll
  15. total 20
  16. -rw-r--r-- 1 root root 11502 Jan 12 12:04 __init__.py
  17. -rw-r--r-- 1 root root 7764 Dec 14 01:39 __init__.pyc
  18. drwxr-xr-x 2 root root 37 Jan 12 11:46 __pycache__
  19. #修改__init__.py文件
  20. def _check_cloudforms_subscription(self):
  21. return True #添加这一行
  22. if os.path.exists('/var/lib/awx/i18n.db'):
  23. return True
  24. else:
  25. if os.path.isdir('/opt/rh/cfme-appliance'):
  26. if os.path.isdir('/opt/rh/cfme-gemset'):
  27. pass
  28. try:
  29. has_rpms = subprocess.call(['rpm', '--quiet', '-q', 'cfme', 'cfme-appliance', 'cfme-gemset'])
  30. if has_rpms == 0:
  31. return True
  32. except OSError:
  33. pass
  34. return False
  35. ....
  36. #修改"license_date=253370764800L" 为 "license_date=253370764800"
  37. def _generate_cloudforms_subscription(self):
  38. self._attrs.update(dict(company_name='Red Hat CloudForms License', instance_count=MAX_INSTANCES,
  39. license_date=253370764800, #修改
  40. license_key='xxxx',
  41. license_type='enterprise',
  42. subscription_name='Red Hat CloudForms License'))
  43. ...
  44. #------------------------------------------------------------------
  45. #修改完重新编译一下
  46. [root@tower tower_license]# python -m py_compile __init__.py
  47. [root@tower tower_license]# python -O -m py_compile __init__.py
  48. [root@tower tower_license]# ll
  49. total 36
  50. -rw-r--r-- 1 root root 11521 Jan 12 12:08 __init__.py
  51. -rw-r--r-- 1 root root 9181 Jan 12 12:08 __init__.pyc
  52. -rw-r--r-- 1 root root 9181 Jan 12 12:08 __init__.pyo
  53. drwxr-xr-x 2 root root 37 Jan 12 11:46 __pycache__
  54. #重启服务
  55. [root@tower tower_license]# ansible-tower-service restart
  56. Restarting Tower
  57. Redirecting to /bin/systemctl stop rh-postgresql10-postgresql.service
  58. Redirecting to /bin/systemctl stop rabbitmq-server.service
  59. Redirecting to /bin/systemctl stop nginx.service
  60. Redirecting to /bin/systemctl stop supervisord.service
  61. Redirecting to /bin/systemctl start rh-postgresql10-postgresql.service
  62. Redirecting to /bin/systemctl start rabbitmq-server.service
  63. Redirecting to /bin/systemctl start nginx.service
  64. Redirecting to /bin/systemctl start supervisord.service

访问https://10.0.0.203/#/license

Ansible-Tower - 图3

四、运行测试项目

playbook 将在 github 上创建,Ansible Tower 拉取执行,Ansible Tower 的 playbook 默认存在 /var/lib/awx/projects/

1)创建 host 登录凭据

Ansible-Tower - 图4

Ansible-Tower - 图5

Ansible-Tower - 图6

2)在 github 中添加 playbook 项目

Ansible-Tower - 图7

3)在 Ansible Tower 添加拉取 github 项目的凭据

Ansible-Tower - 图8

4)创建 project

Ansible-Tower - 图9

保存后 Ansilble Tower 会自动运行一次 Update,如果要手动运行,点击列表中的刷新按钮。当 github 上 yml 文件被更新或者新增后需要点击一下刷新按钮,否则 JOB 执行得还是原来的 yml

Ansible-Tower - 图10

Ansible-Tower - 图11

此时在 Ansible Tower 服务器的 / var/lib/awx/projects / 目录下已经有 git 拉下来的完整文件结构

Ansible-Tower - 图12

5)创建主机清单

Ansible-Tower - 图13

Ansible-Tower - 图14

6)创建任务模板

Ansible-Tower - 图15

7)运行模板

Ansible-Tower - 图16

Ansible-Tower - 图17

点击右侧日志中 change 几行可以看到详细信息

Ansible-Tower - 图18

Ansible-Tower - 图19

五、安装 tomcat8 测试

1)编写 playbook

Ansible-Tower - 图20

  1. ---
  2. - hosts: all
  3. remote_user: root
  4. tasks:
  5. - name: "copy files to remote host"
  6. copy:
  7. src={{ item.src }}
  8. dest={{ item.dest }}
  9. with_items:
  10. - src: /usr/local/src/jdk-8u162-linux-x64.rpm
  11. dest: /usr/local/
  12. - src: /usr/local/src/apache-tomcat-8.0.38.tar.gz
  13. dest: /usr/local/
  14. - name: "install jdk"
  15. yum:
  16. name: /usr/local/jdk-8u162-linux-x64.rpm
  17. state: present
  18. - name: "install tomcat8"
  19. shell: cd /usr/local/ && tar xf apache-tomcat-8.0.38.tar.gz
  20. - name: "rename file"
  21. shell: mv /usr/local/apache-tomcat-8.0.38 /usr/local/tomcat8
  22. - name: "start tomcat"
  23. shell: 'nohup /usr/local/tomcat8/bin/startup.sh &'

2)创建 inventory

Ansible-Tower - 图21

Ansible-Tower - 图22

3)创建 project

Ansible-Tower - 图23

4)创建模板

Ansible-Tower - 图24

5)运行模板

Ansible-Tower - 图25

6)浏览器测试 tomcat

http://10.0.0.204:8080/

Ansible-Tower - 图26

https://www.cnblogs.com/hujinzhong/p/12172903.html