Background Image
Table of Contents Table of Contents
Previous Page  452 / 478 Next Page
Information
Show Menu
Previous Page 452 / 478 Next Page
Page Background

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 virtualenv 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 nginx

The vars section defines a variable “host” for convenience, which we can then use in the

various filenames and pass to the config files themselves. It comes from

$inventory_hostname

, which is the domain name of the server we’re running against

at the time.

In this section, we install our required software using

apt

, tweak the Nginx config to

allow long hostnames using a regular expression replacer, and then we write the Nginx

config file using a template. This is a modified version of the template file we saved into

deploy_tools/nginx.template.conf

in

Chapter 8

, but it now uses a specific templating

syntax—Jinja2, which is actually a lot like the Django template syntax:

deploy_tools/nginx.conf.j2.

server {

listen 80;

server_name {{ host }};

location /static {

424

|

Appendix C: Provisioning with Ansible