1. 程式人生 > >ansible自動部署網站

ansible自動部署網站

一、架構

1.主機

ansible+haproxy+(RS1&RS2)

2.mark down方式

haproxy基於內容檢測後端RS

二、play-book檔案

vim /etc/ansible/hosts

[nginx-web]
        192.168.17.175
        192.168.17.176
vim  /etc/ansible/web.yml

---
- hosts: nginx-web
  remote_user: root
  serial: 1
  vars: 
  - check: /data/web/xiaomi/check.html 
tasks: - name: state_down copy: content="down" dest={{ check }} - name: sleep shell: sleep 5 - name: stop_servive service: name={{ item }} state=stopped with_items: - nginx - php-fpm - name: deploy copy: src=/tmp/xiaomi1 dest=/data/web/ force=yes - name: link file: src=/data/web/xiaomi1 dest=/data/web/xiaomi state=link - name:
state_ok
copy: content="ok" dest={{ check }} - name: start_service service: name={{ item }} state=started with_items: - nginx - php-fpm