Ansible Vault概述
Ansible Vault做為Ansible的一項新功能,可將例如:password,keys等敏感資料檔案進行加密處理,而非存放在明文的playbook中或roles中,
Ansible Vault使用
usage: ansible-vault [-h] [--version] [-v]
{create,decrypt,edit,view,encrypt,encrypt_string,rekey}
## 加密
ansible-vault encrypt mysql.yml
## 查看加密后的playbook
ansible-vault view mysql.yml
## 編輯加密后的playbook
ansible-vault edit mysql.yml
## 解密
ansible-vault decrypt mysql.yml
## 運行加密后的vault
vim /tmp/ap.txt
123
ansible-playbook mysql.yml --vault-password-file=/tmp/ap.txt
## 改密碼
ansible-vault rekey mysql.yml
Ansible Tower
什么是Ansible Tower
Ansible Tower是由Redhat提供的一個管理Ansible前端UI,使用它可以免費管理10臺以內的主機,所以它是一個收費專案,該專案僅適用于那些不會運維開發,并且有錢的選手們,當然,如果會開發,懶得寫,也可以 PJ AnsibleTower,Do you understand me?
Ansible本質上是一個進行了封裝的Shell,優點在于它是去中心化的工具,可以直接通過ssh管理遠程主機,實作無Agent的部署(ssh+python環境已經原生集成在Linux中),
Ansible的缺點也在于其去中心化的特點,本身不支持高可用和分布式架構,無法實作Server-Proxy-Client的架構,在比較復雜或者多區域的網路區域中,無法實作統一的集中式管理(如多個ansible管理端的配置同步),也沒有前端UI,對ansible的技能要求比較高
Ansible Tower 架構

部署Ansible Tower
# 1.創建安裝目錄
[root@web03 ~]# mkdir /root/ansible
# 2.進入目錄
[root@web03 ~]# cd /root/ansible
# 3.下載安裝包
[root@web03 ansible]# wget http://test.driverzeng.com/other/ansible-tower-setupbundle-3.6.2-1.el7.tar.gz
# 4.解壓
[root@web03 ansible]# ll
-rw-r--r-- 1 root root 293849789 Dec 14 2019 ansible-tower-setup-bundle-3.6.2-
1.el7.tar.gz
[root@web03 ansible]# du -sh ansible-tower-setup-bundle-3.6.2-1.el7.tar.gz
281M ansible-tower-setup-bundle-3.6.2-1.el7.tar.gz
[root@web03 ansible]# tar xf ansible-tower-setup-bundle-3.6.2-1.el7.tar.gz
[root@web03 ansible]# ll
total 286964
drwxr-xr-x 6 root root 190 Dec 14 2019 ansible-tower-setup-bundle-3.6.2-1
# 5.進入安裝目錄
[root@web03 ansible-tower-setup-bundle-3.6.2-1]# ll
total 52
-rw-r--r-- 1 root root 562 Dec 14 2019 backup.yml
drwxr-xr-x 4 root root 28 Dec 14 2019 bundle
drwxr-xr-x 2 root root 17 Dec 14 2019 group_vars
-rw-r--r-- 1 root root 7410 Dec 14 2019 install.yml
-rw-r--r-- 1 root root 1148 Dec 14 2019 inventory
drwxr-xr-x 3 root root 8192 Dec 14 2019 licenses
-rw-r--r-- 1 root root 2526 Dec 14 2019 README.md
-rw-r--r-- 1 root root 1335 Dec 14 2019 rekey.yml
-rw-r--r-- 1 root root 1393 Dec 14 2019 restore.yml
drwxr-xr-x 20 root root 312 Dec 14 2019 roles
-rwxr-xr-x 1 root root 11405 Dec 14 2019 setup.sh
# 6.修改inventory檔案
[tower]
localhost ansible_connection=local
[database]
[all:vars]
admin_password='tower' #tower登錄密碼
pg_host=''
pg_port=''
pg_database='awx'
pg_username='awx'
pg_password='tower'
pg_sslmode='prefer' # set to 'verify-full' for client-side enforced SSL
rabbitmq_username=tower
rabbitmq_password='tower'
rabbitmq_cookie=cookiemonster
# 7.安裝
[root@web03 ansible-tower-setup-bundle-3.6.2-1]# ./setup.sh
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-wYIfKVtY-1629375694871)(D:\圖片\tower安裝成功.png)]
安裝成功
瀏覽器打開 10.0.0.9
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-zeAUr1je-1629375694873)(D:\圖片\tower用瀏覽器打開.png)]
Ansible Tower 反向解
# 1.安裝python環境
[root@web03 ansible-tower-setup-bundle-3.6.2-1]# yum install -y python36-devel
# 2.安裝uncompyle6
[root@zabbix01 tower_license]# pip3 install uncompyle6 -i
https://pypi.douban.com/simple
# 3.反編譯代碼
進入代碼目錄
[root@web03 ~]# cd /var/lib/awx/venv/awx/lib/python3.6/site-packages/tower_license
[root@web03 tower_license]# uncompyle6 __init__.pyc >__init__.py
# 4.修改檔案
def _check_cloudforms_subscription(self):
return Ture
# 5.備份原來的pyc檔案
[root@web03 tower_license]# mv __init__.pyc __init__.pyc.bak
# 6.編譯代碼.py
[root@web03 tower_license]# python -m py_compile __init__.py
[root@web03 tower_license]# python -O -m py_compile __init__.py
# 7.重啟服務
[root@web03 tower_license]# ansible-tower-service restart
Restarting Tower
Redirecting to /bin/systemctl stop rh-postgresql10-postgresql.service
Redirecting to /bin/systemctl stop rabbitmq-server.service
Redirecting to /bin/systemctl stop nginx.service
Redirecting to /bin/systemctl stop supervisord.service
Redirecting to /bin/systemctl start rh-postgresql10-postgresql.service
Redirecting to /bin/systemctl start rabbitmq-server.service
Redirecting to /bin/systemctl start nginx.service
Redirecting to /bin/systemctl start supervisord.service
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-asn7QPfd-1629375694876)(D:\圖片\tower反向解.png)]
Ansible Tower 使用
先創建連接虛擬機的方式

選擇使用密碼或者秘鑰

創建主機清單

添加主機

添加專案

編輯playbook
# 1.進入ansible tower指定目錄
[root@web03 tower_license]# cd /var/lib/awx/projects
# 2.創建目錄
[root@web03 projects]# mkdir ip
# 3.編輯playbook
[root@web03 projects]# vim ip/get_ifconfig.yml
- hosts: all
tasks:
- name: Get Ifconfig
shell: 'ifconfig'
# 4.授權
[root@web03 projects]# chown awx.awx -R /var/lib/awx/projects/
創建執行模板

執行結果

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/295242.html
標籤:區塊鏈
