From ecea858455e736cbd1b90839f3c5cdde658abe2c Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Sun, 8 Jan 2017 16:31:38 -0800 Subject: [PATCH] Updating chapter 8 --- ch08/playbooks/roles/database/handlers/main.yml | 2 +- ch08/playbooks/roles/database/tasks/main.yml | 17 ++++++++++------- .../playbooks/roles/mezzanine/handlers/main.yml | 4 ++-- ch08/playbooks/roles/mezzanine/tasks/django.yml | 4 ++-- ch08/playbooks/roles/mezzanine/tasks/main.yml | 2 +- ch08/playbooks/roles/mezzanine/tasks/nginx.yml | 8 ++++---- .../mezzanine/templates/gunicorn.conf.py.j2 | 5 +++-- ch08/playbooks/roles/mezzanine/vars/main.yml | 11 +++++------ 8 files changed, 28 insertions(+), 25 deletions(-) diff --git a/ch08/playbooks/roles/database/handlers/main.yml b/ch08/playbooks/roles/database/handlers/main.yml index b835c90..4b53914 100644 --- a/ch08/playbooks/roles/database/handlers/main.yml +++ b/ch08/playbooks/roles/database/handlers/main.yml @@ -1,4 +1,4 @@ --- - name: restart postgres service: name=postgresql state=restarted - sudo: True + become: True diff --git a/ch08/playbooks/roles/database/tasks/main.yml b/ch08/playbooks/roles/database/tasks/main.yml index d8a2e16..9170395 100644 --- a/ch08/playbooks/roles/database/tasks/main.yml +++ b/ch08/playbooks/roles/database/tasks/main.yml @@ -1,7 +1,7 @@ --- - name: install apt packages apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 - sudo: True + become: True with_items: - libpq-dev - postgresql @@ -10,20 +10,23 @@ copy: > src=postgresql.conf dest=/etc/postgresql/9.3/main/postgresql.conf owner=postgres group=postgres mode=0644 - sudo: True + become: True notify: restart postgres - name: copy client authentication configuration file copy: > src=pg_hba.conf dest=/etc/postgresql/9.3/main/pg_hba.conf owner=postgres group=postgres mode=0640 - sudo: True + become: True notify: restart postgres +- name: create project locale + locale_gen: name={{ locale }} + become: True - name: create a user postgresql_user: name: "{{ database_user }}" password: "{{ db_pass }}" - sudo: True - sudo_user: postgres + become: True + become_user: postgres - name: create the database postgresql_db: name: "{{ database_name }}" @@ -32,5 +35,5 @@ lc_ctype: "{{ locale }}" lc_collate: "{{ locale }}" template: template0 - sudo: True - sudo_user: postgres + become: True + become_user: postgres diff --git a/ch08/playbooks/roles/mezzanine/handlers/main.yml b/ch08/playbooks/roles/mezzanine/handlers/main.yml index 59e71cb..0913020 100644 --- a/ch08/playbooks/roles/mezzanine/handlers/main.yml +++ b/ch08/playbooks/roles/mezzanine/handlers/main.yml @@ -1,7 +1,7 @@ --- - name: restart supervisor supervisorctl: name=gunicorn_mezzanine state=restarted - sudo: True + become: True - name: restart nginx service: name=nginx state=restarted - sudo: True + become: True diff --git a/ch08/playbooks/roles/mezzanine/tasks/django.yml b/ch08/playbooks/roles/mezzanine/tasks/django.yml index bb17ba1..19d453d 100644 --- a/ch08/playbooks/roles/mezzanine/tasks/django.yml +++ b/ch08/playbooks/roles/mezzanine/tasks/django.yml @@ -40,11 +40,11 @@ template: src=gunicorn.conf.py.j2 dest={{ mezzanine_proj_path }}/gunicorn.conf.py - name: set the supervisor config file template: src=supervisor.conf.j2 dest=/etc/supervisor/conf.d/mezzanine.conf - sudo: True + become: True notify: restart supervisor - name: ensure config path exists file: path={{ mezzanine_conf_path }} state=directory - sudo: True + become: True when: tls_enabled - name: install poll twitter cron job cron: > diff --git a/ch08/playbooks/roles/mezzanine/tasks/main.yml b/ch08/playbooks/roles/mezzanine/tasks/main.yml index 7ac8e3a..975a15e 100644 --- a/ch08/playbooks/roles/mezzanine/tasks/main.yml +++ b/ch08/playbooks/roles/mezzanine/tasks/main.yml @@ -1,7 +1,7 @@ --- - name: install apt packages apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 - sudo: True + become: True with_items: - git - libjpeg-dev diff --git a/ch08/playbooks/roles/mezzanine/tasks/nginx.yml b/ch08/playbooks/roles/mezzanine/tasks/nginx.yml index 41482e8..1852181 100644 --- a/ch08/playbooks/roles/mezzanine/tasks/nginx.yml +++ b/ch08/playbooks/roles/mezzanine/tasks/nginx.yml @@ -1,24 +1,24 @@ - name: set the nginx config file template: src=nginx.conf.j2 dest=/etc/nginx/sites-available/mezzanine.conf notify: restart nginx - sudo: True + become: True - name: enable the nginx config file file: src: /etc/nginx/sites-available/mezzanine.conf dest: /etc/nginx/sites-enabled/mezzanine.conf state: link notify: restart nginx - sudo: True + become: True - name: remove the default nginx config file file: path=/etc/nginx/sites-enabled/default state=absent notify: restart nginx - sudo: True + become: True - name: create ssl certificates command: > openssl req -new -x509 -nodes -out {{ mezzanine_proj_name }}.crt -keyout {{ mezzanine_proj_name }}.key -subj '/CN={{ domains[0] }}' -days 3650 chdir={{ mezzanine_conf_path }} creates={{ mezzanine_conf_path }}/{{ mezzanine_proj_name }}.crt - sudo: True + become: True when: tls_enabled notify: restart nginx diff --git a/ch08/playbooks/roles/mezzanine/templates/gunicorn.conf.py.j2 b/ch08/playbooks/roles/mezzanine/templates/gunicorn.conf.py.j2 index 77f9872..c12307c 100644 --- a/ch08/playbooks/roles/mezzanine/templates/gunicorn.conf.py.j2 +++ b/ch08/playbooks/roles/mezzanine/templates/gunicorn.conf.py.j2 @@ -1,7 +1,8 @@ from __future__ import unicode_literals import multiprocessing -bind = "127.0.0.1:{{ mezzanine_gunicorn_port }}" -workers = multiprocessing.cpu_count() * 2 + 1 +bind = "unix:{{ mezzanine_proj_path }}/gunicorn.sock" +workers = {{ mezzanine_num_workers }} +errorlog = "/home/{{ mezzanine_user }}/logs/{{ mezzanine_proj_name }}_error.log" loglevel = "error" proc_name = "{{ mezzanine_proj_name }}" diff --git a/ch08/playbooks/roles/mezzanine/vars/main.yml b/ch08/playbooks/roles/mezzanine/vars/main.yml index 40d1c79..657d868 100644 --- a/ch08/playbooks/roles/mezzanine/vars/main.yml +++ b/ch08/playbooks/roles/mezzanine/vars/main.yml @@ -1,13 +1,12 @@ --- # vars file for mezzanine mezzanine_user: "{{ ansible_user }}" -mezzanine_venv_home: "{{ ansible_env.HOME }}" -mezzanine_venv_path: "{{ mezzanine_venv_home }}/{{ mezzanine_proj_name }}" -mezzanine_repo_url: git@github.com:lorin/mezzanine-example.git -mezzanine_proj_dirname: project -mezzanine_proj_path: "{{ mezzanine_venv_path }}/{{ mezzanine_proj_dirname }}" +mezzanine_venv_home: "{{ ansible_env.HOME }}/.virtualenvs" +mezzanine_venv_path: "{{ venv_home }}/{{ proj_name }}" +mezzanine_repo_url: git@github.com:ansiblebook/mezzanine_example.git +mezzanine_proj_path: "{{ ansible_env.HOME }}/mezzanine/{{ mwzzanine_proj_name }}" mezzanine_reqs_path: requirements.txt mezzanine_conf_path: /etc/nginx/conf mezzanine_python: "{{ mezzanine_venv_path }}/bin/python" mezzanine_manage: "{{ mezzanine_python }} {{ mezzanine_proj_path }}/manage.py" -mezzanine_gunicorn_port: 8000 +mezzanine_num_workers: "multiprocessing.cpu_count() * 2 + 1" -- 2.44.0