S小魚仔S 網誌搜尋

2018年7月25日 星期三

S小魚仔S Centos 7 搭建 Ansible awx 套件 提供 UI 介面操作

Ansible Awx (免費) 提供可視化操作介面,開始進行佈署「Ansible Awx」。

#==修改「電腦」名稱 ( SVN )====
hostnamectl set-hostname ansible_awx

#==關閉「selinux 」======
#關閉「Selinux」為「disabled」才不會阻擋「服務連線」服務
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

#==設定 Firewall========

#加入「防火牆」規則 Web UI
sudo firewall-cmd --add-port=80/tcp --permanent

#重新啟動「防火牆」
sudo firewall-cmd --reload


#==更新「Yum」源
yum install -y epel-release

#安裝「postgresq.rpm」更新「yum」源
yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm

#安裝「postgresql」
yum install postgresql96-server -y

#安裝「rabbitmq-server」、「wget」、「memcached」、「nginx」、「ansible」
yum install -y rabbitmq-server wget memcached nginx ansible

#下載「mrmeee-awx-epel-7.repo」套件
wget -O /etc/yum.repos.d/awx-rpm.repo https://copr.fedorainfracloud.org/coprs/mrmeee/awx/repo/epel-7/mrmeee-awx-epel-7.repo

#安裝「awx」
yum install -y awx

#初始化「postgresql」資料庫
/usr/pgsql-9.6/bin/postgresql96-setup initdb

#启动rabbitmq服务
systemctl enable rabbitmq-server
systemctl start rabbitmq-server

#启动Mpostgresql服务
systemctl enable postgresql-9.6
systemctl start postgresql-9.6

#启动Memcached服务
systemctl enable memcached
systemctl start memcached

#创建Postgres用户
sudo -u postgres createuser -S awx

#创建Postgres 数据库
sudo -u postgres createdb -O awx awx

#将数据导入数据库
sudo -u awx /opt/awx/bin/awx-manage migrate

#===初始化 Ansible AWX ====
echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'root@localhost', 'password')" | sudo -u awx /opt/awx/bin/awx-manage shell

sudo -u awx /opt/awx/bin/awx-manage create_preload_data

sudo -u awx /opt/awx/bin/awx-manage provision_instance --hostname=$(hostname)

sudo -u awx /opt/awx/bin/awx-manage register_queue --queuename=tower --hostnames=$(hostname)


#===配置Nginx===

#備份來源「nginx.conf」
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bkp

#替换nginx conf文件
wget -O /etc/nginx/nginx.conf https://raw.githubusercontent.com/sunilsankar/awx-build/master/nginx.conf

#啟動「Nginx」
systemctl start nginx
systemctl enable nginx


#==========啟動「Awx」相關「程序」
systemctl start awx-cbreceiver
systemctl start awx-celery-beat
systemctl start awx-celery-worker
systemctl start awx-channels-worker
systemctl start awx-daphne
systemctl start awx-web

#=========開機自動啟動「Awx」相關「程序」
systemctl enable awx-cbreceiver
systemctl enable awx-celery-beat
systemctl enable awx-celery-worker
systemctl enable awx-channels-worker
systemctl enable awx-daphne
systemctl enable awx-web

#====需要「Reboot」重開機====
reboot -h now


接下來輸入「http://ip」 ( User: admin Password: password )


Ansible Awx 安裝完成


#===Ansible AWX 有 Bug 必須使用以下指令修復 ( 2019/09/25 ) 更新 ===
PS. 如果不修復任務會一直處於「pending」狀態 

sudo -u awx scl enable rh-python36 rh-postgresql10 "awx-manage create_preload_data"
sudo -u awx scl enable rh-python36 rh-postgresql10 "awx-manage provision_instance --hostname=$(hostname)"
sudo -u awx scl enable rh-python36 rh-postgresql10 "awx-manage register_queue --queuename=tower --hostnames=$(hostname)"
  
systemctl restart awx-cbreceiver
systemctl restart awx-dispatcher
systemctl restart awx-channels-worker
systemctl restart awx-daphne
systemctl restart awx-web

參考資料