附录 C 使用 Ansible 配置服务器
# deploy_tools/inventory.ansible
[live]
watch0.top
[staging]
watch0-staging.top
[local]
localhost ansible_ssh_port=6666 ansible_host=127.0.0.1C.1 安装系统包和 Nginx
# deploy_tools/provision.ansible.yaml
---
- hosts: all
sudo: yes
vars: host:$inventory_hostname
tasks:
- name: make sure required packages are installed
apt: pkg=nginx, git, python3, python3-pip, state=present
- name: make sure virtual is installed
shell: pip3 install virtualenv
- name: allow long hostnames in nginx
lineinfile:
dest=/etc/nginx/nginx.conf
regexp='(\s+)#? ?server_names_hash_bucket_size'
backrefs=yes
line='\1server_names_hash_bucket_size 64;'
- name: add nginx config to sites-available
template: src=./nginx.conf.j2
dest=/etc/nginx/sites-available/{{ host }}
notify:
- restart nginx
- name: add symlink in nginx sites-enabled
file: src=/etc/nginx/sites-available/{{ host }}
dest=/etc/nginx/sites-enabled/{{ host }} state=link
notify:
- restart nginxC.2 配置 Gunicron,使用处理程序重启服务
C.3 接下来做什么
C.3.1 把 Fabric 执行的部署操作交给 Ansible
C.3.2 使用 Vagrant 搭建本地虚拟主机
Last updated