Changeset - 480828d2ad47
[Not reviewed]
0 6 2
Branko Majic (branko) - 7 years ago 2017-08-21 12:25:37
branko@majic.rs
MAR-118: Replaced handler with parametrised name in wsgi_website:

- Updated wsgi_website role.
- Replaced handler with parametrised name used for restarting a single service
with a generic handler that will restart zero or more services.
- Updated test site roles to introduce explicit handler in them.
- Updated usage instructions to include set-up of explicit handler for
restarting the Wiki service.
8 files changed with 67 insertions and 12 deletions:
0 comments (0 inline, 0 general)
docs/usage.rst
Show inline comments
 
@@ -1649,7 +1649,7 @@ on the safe side:
 
           - settings.py
 
           - urls.py
 
        notify:
 
           - Restart website wiki.example.com
 
           - Restart wiki
 

	
 
      - name: Deploy project database and deploy static files
 
        django_manage: command="{{ item }}"
 
@@ -1674,6 +1674,16 @@ on the safe side:
 
        register: wiki_superuser
 
        changed_when: wiki_superuser.stdout == "Created superuser."
 

	
 
   :file:`~/mysite/roles/wiki/handlers/main.yml`
 
   ::
 

	
 
      ---
 

	
 
      - name: Restart wiki
 
        service:
 
          name: wiki.example.com
 
          state: restarted
 

	
 
5. There is a couple of files that we are deploying through the above
 
   tasks. Let's create them as well.
 

	
roles/wsgi_website/handlers/main.yml
Show inline comments
 
---
 

	
 
- name: "Restart website {{ fqdn }}"
 
- name: Restart WSGI services
 
  service:
 
    name: "{{ fqdn }}"
 
    name: "{{ item }}"
 
    state: restarted
 
  with_items: "{{ wsgi_services_to_restart }}"
roles/wsgi_website/tasks/main.yml
Show inline comments
 
@@ -74,8 +74,9 @@
 
    name: "{{ item }}"
 
    state: present
 
  with_items: "{{ packages }}"
 
  register: install_extra_packages
 
  notify:
 
    - "Restart website {{ fqdn }}"
 
    - Restart WSGI services
 

	
 
- name: Set-up MariaDB mysql_config symbolic link for compatibility (workaround for Debian bug 766996)
 
  file:
 
@@ -134,8 +135,9 @@
 
    - package: futures
 
      version: "{{ futures_version }}"
 
  when: "not wsgi_requirements"
 
  register: install_wsgi_server
 
  notify:
 
    - "Restart website {{ fqdn }}"
 
    - Restart WSGI services
 

	
 
- include: requirements.yml
 
  when: "wsgi_requirements"
 
@@ -148,8 +150,9 @@
 
    state: present
 
    virtualenv: "{{ home }}/virtualenv"
 
  with_items: "{{ virtualenv_packages }}"
 
  register: install_additional_packages_in_virtualenv
 
  notify:
 
    - "Restart website {{ fqdn }}"
 
    - Restart WSGI services
 

	
 
- name: Deploy systemd socket configuration for website
 
  template:
 
@@ -158,9 +161,10 @@
 
    owner: root
 
    group: root
 
    mode: 0644
 
  register: deploy_systemd_socket_configuration
 
  notify:
 
    - Reload systemd
 
    - "Restart website {{ fqdn }}"
 
    - Restart WSGI services
 

	
 
- name: Deploy systemd service configuration for website
 
  template:
 
@@ -169,9 +173,10 @@
 
    owner: root
 
    group: root
 
    mode: 0644
 
  register: deploy_systemd_service_configuration
 
  notify:
 
    - Reload systemd
 
    - "Restart website {{ fqdn }}"
 
    - Restart WSGI services
 

	
 
- name: Enable the website service
 
  service:
 
@@ -234,6 +239,32 @@
 
  notify:
 
    - Restart nginx
 

	
 
- name: Set-up empty list of WSGI services to restart
 
  set_fact:
 
    wsgi_services_to_restart: []
 
  when: "wsgi_services_to_restart is not defined"
 
  tags:
 
    - handlers
 

	
 
- name: Add service to list of WSGI services to restart
 
  set_fact:
 
    wsgi_services_to_restart: "{{ wsgi_services_to_restart + [ fqdn ] }}"
 
  when: |
 
    fqdn not in wsgi_services_to_restart and
 
    ((install_extra_packages is defined and install_extra_packages.changed) or
 
    (install_wsgi_server is defined and install_wsgi_server.changed) or
 
    (install_additional_packages_in_virtualenv is defined and install_additional_packages_in_virtualenv.changed) or
 
    (deploy_systemd_socket_configuration is defined and deploy_systemd_socket_configuration.changed) or
 
    (deploy_systemd_service_configuration is defined and deploy_systemd_service_configuration.changed) or
 
    (install_gunciron_via_requirements is defined and install_gunciron_via_requirements.changed) or
 
    (handlers | default(False) | bool() == True))
 
  tags:
 
    - handlers
 
    # [ANSIBLE0016] Tasks that run when changed should likely be handlers
 
    #   This specific task is used in order to work around inability of Ansible
 
    #   to provide properly parametrised handlers for reusable roles.
 
    - skip_ansible_lint
 

	
 
- name: Explicitly run all handlers
 
  include: ../handlers/main.yml
 
  when: "handlers | default(False) | bool() == True"
roles/wsgi_website/tasks/requirements.yml
Show inline comments
 
@@ -36,5 +36,6 @@
 
    requirements: "{{ home }}/.wsgi_requirements.txt"
 
    state: present
 
    virtualenv: "{{ home }}/virtualenv"
 
  register: install_gunciron_via_requirements
 
  notify:
 
    - "Restart website {{ fqdn }}"
 
    - Restart WSGI services
testsite/playbooks/roles/wsgihello/handlers/main.yml
Show inline comments
 
new file 100644
 
---
 

	
 
- name: Restart wsgihello
 
  service:
 
    name: "wsgi.{{ testsite_domain }}"
 
    state: restarted
testsite/playbooks/roles/wsgihello/tasks/main.yml
Show inline comments
 
@@ -8,4 +8,4 @@
 
  copy: src="hello.wsgi" dest="/var/www/wsgi.{{ testsite_domain }}/code/wsgi.py"
 
        owner="admin-wsgi_{{ testsite_domain_underscores }}" group="web-wsgi_{{ testsite_domain_underscores }}" mode=640
 
  notify:
 
    - Restart website wsgi.{{ testsite_domain }}
 
\ No newline at end of file
 
    - Restart wsgihello
testsite/playbooks/roles/wsgihello2/handlers/main.yml
Show inline comments
 
new file 100644
 
---
 

	
 
- name: Restart wsgihello2
 
  service:
 
    name: "wsgireq.{{ testsite_domain }}"
 
    state: restarted
testsite/playbooks/roles/wsgihello2/tasks/main.yml
Show inline comments
 
@@ -29,10 +29,10 @@
 
  register: pip_sync_result
 
  changed_when: "pip_sync_result.stdout != 'Everything up-to-date'"
 
  notify:
 
    - Restart website wsgireq.{{ testsite_domain }}
 
    - Restart wsgihello2
 

	
 
- name: Deploy WSGI application
 
  copy: src="hello.wsgi" dest="/var/www/wsgireq.{{ testsite_domain }}/code/wsgi.py"
 
        owner="admin-wsgireq_{{ testsite_domain_underscores }}" group="web-wsgireq_{{ testsite_domain_underscores }}" mode=640
 
  notify:
 
    - Restart website wsgireq.{{ testsite_domain }}
 
\ No newline at end of file
 
    - Restart wsgihello2
0 comments (0 inline, 0 general)