Ansible-Tower--安裝配置及破解


一、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

image-20200729135055264

需要認證:

image

三、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]#

修改如下:

image-20200729140141494

#訪問https://192.168.1.116/#/license

image-20200729140255487

四、運行測試項目

playbook將在github上創建,Ansible Tower拉取執行,Ansible Tower的playbook默認存在 /var/lib/awx/projects/

1)創建host登錄憑據

[image

image-20200729140503839

image-20200729140535697

2)在gitlab中添加playbook項目

image-20200729140607352

3)在Ansible Tower添加拉取github項目的憑據

image-20200729140709052

4)創建project

image-20200729140751133

保存后Ansilble Tower會自動運行一次Update,如果要手動運行,點擊列表中的刷新按鈕。當gitlab上yml文件被更新或者新增后需要點擊一下刷新按鈕,否則JOB執行得還是原來的yml

image-20200729140917270

image-20200729141009889

此時在Ansible Tower服務器的/var/lib/awx/projects/目錄下已經有git拉下來的完整文件結構

image-20200729141056513

5)創建主機清單

image-20200729141457834

image-20200729141528951

6)創建任務模板

image-20200729141656898

7)運行模板

image

image-20200729141734566

點擊右側日志中change幾行可以看到詳細信息

image-20200729141807351

五、安裝tomcat8測試

1)編寫playbook

image-20200729141840640

---
- 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

image-20200729142451378

image-20200729142515452

3)創建project

image-20200729142617449

4)創建模板

image-20200729142648338

5)運行模板

image-20200729142714190

6)瀏覽器測試tomcat

http://192.168.1.116:8080/

image-20200729142336168

參考文檔:https://www.cnblogs.com/hujinzhong/p/12172903.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM