Ansible 实战之部署Web架构

WEB架构(ubuntu 16.04): 

Proxy -- WebServer(Nginx+PHP+Django) -- Nosql -- MariaDB

一、 定义Inventory

[proxy]
192.168.20.180

[app]
192.168.20.181
192.168.20.182 [nosql] 192.168.20.183 [db] 192.168.20.184

 

二、Proxy安装Nginx

ansible proxy -m apt -a "name=nginx state=present"

ansible proxy -m command -a "/etc/init.d/nginx status"

 

三、APP安装php

ansible app -m apt -a "name=php state=present"

ansible app -m command -a "/etc/init.d/php7.0-fpm status"

 

四、APP安装Django

ansible app -m apt -a "name=django state=present"

ansible app -m command -a "python -c 'import django; print django.get_version()' "

 

五、NoSQL安装redis

ansible nosql -m apt -a "name=redis-server state=present"

ansible nosql -m command -a "redis-cli --version"

 

六、DB安装mariadb

ansible db -m apt -a "name=mariadb-server state=present"

ansible db -m command -a "/etc/init.d/mysql status"

 

七、启动服务

root@ubuntu:~# ansible webserver -m service -a "name=rabbitmq-server state=started enabled=yes"
192.168.20.180 | SUCCESS => {
    "changed": false, 
    "enabled": true, 
    "name": "rabbitmq-server", 
    "state": "started"
}
192.168.20.182 | SUCCESS => {
    "changed": false, 
    "enabled": true, 
    "name": "rabbitmq-server", 
    "state": "started"
}
root@ubuntu:~# 

  

posted @ 2017-04-01 23:15  Vincen_shen  阅读(1197)  评论(0编辑  收藏  举报