Changeset - 2b3af82bc50e
[Not reviewed]
0 3 5
Branko Majic (branko) - 7 years ago 2017-04-19 23:03:15
branko@majic.rs
MAR-98: Updated testsite to include another WSGI hello world role that utilises wsgi_requirements in wsgi_website role, as well as pip-tools. Purposefully installs some outdated packages for testing the upgrade checks.
8 files changed with 104 insertions and 0 deletions:
0 comments (0 inline, 0 general)
docs/testsite.rst
Show inline comments
 
@@ -86,6 +86,7 @@ In order to deploy the test site, the following steps would normally be taken:
 
   - ``testsite/tls/web.example.com_https.key``
 
   - ``testsite/tls/phpfino.example.com_https.key``
 
   - ``testsite/tls/wsgi.example.com_https.key``
 
   - ``testsite/tls/wsgireq.example.com_https.key``
 

	
 
4. Issue TLS certificates corresponding to the generated TLS private keys
 
   (correct FQDN for DNS subject alternative name **must** be used), making sure
 
@@ -107,6 +108,8 @@ In order to deploy the test site, the following steps would normally be taken:
 
     should be ``phpinfo.example.com``)
 
   - ``testsite/tls/wsgi.example.com_https.pem`` (subject alternative name
 
     should be ``wsgi.example.com``)
 
   - ``testsite/tls/wsgireq.example.com_https.pem`` (subject alternative name
 
     should be ``wsgireq.example.com``)
 

	
 
5. Create ``PEM`` truststore file which contains all CA certificates that form
 
   CA chain for the issued end entity certificates from previous step at
testsite/playbooks/roles/wsgihello2/files/hello.wsgi
Show inline comments
 
new file 100644
 
#!/usr/bin/env python
 

	
 
import os
 
import ipcalc
 

	
 
def application(environ, start_response):
 
    status = '200 OK'
 

	
 
    template = """<!DOCTYPE html>
 
<html lang="en">
 
  <head>
 
    <meta charset="utf-8">
 
    <title>{title}</title>
 
  </head>
 
  <body>
 
    <h1>Hello, world!</h1>
 
    <p>I am website {title}</p>
 
    <p>Accept-Encoding header was set to {acceptencoding}</p>
 
    <p>Available IP range for subnet {subnet} is from {subnet_first} to {subnet_last}</p>
 
  </body>
 
</html>
 
"""
 
    subnet = ipcalc.Network('10.128.128.0/24')
 

	
 
    output = template.format(title=os.environ.get("WEBSITE_NAME", "that nobody set a name for :("),
 
                             acceptencoding=environ.get("HTTP_ACCEPT_ENCODING"),
 
                             subnet=str(subnet),
 
                             subnet_first=subnet.host_first(),
 
                             subnet_last=subnet.host_last())
 

	
 
    response_headers = [('Content-type', 'text/html'),
 
                        ('Content-Length', str(len(output)))]
 
    start_response(status, response_headers)
 

	
 
    return [output]
testsite/playbooks/roles/wsgihello2/files/requirements.in
Show inline comments
 
new file 100644
 
ipcalc
 
\ No newline at end of file
testsite/playbooks/roles/wsgihello2/files/requirements.txt
Show inline comments
 
new file 100644
 
ipcalc==1.1.3
testsite/playbooks/roles/wsgihello2/meta/main.yml
Show inline comments
 
new file 100644
 
---
 

	
 
dependencies:
 
  - role: wsgi_website
 
    fqdn: wsgireq.{{ testsite_domain }}
 
    admin_uid: 3002
 
    uid: 2002
 
    wsgi_application: wsgi:application
 
    static_locations:
 
      - /static/
 
    https_tls_key: "{{ lookup('file', inventory_dir + '/tls/wsgireq.' + testsite_domain + '_https.key') }}"
 
    https_tls_certificate: "{{ lookup('file', inventory_dir + '/tls/wsgireq.' + testsite_domain + '_https.pem') }}"
 
    environment_variables:
 
      WEBSITE_NAME: "Majic Ansible Roles Test Site"
 
    wsgi_requirements:
 
      - futures==3.0.1
 
      - gunicorn==19.6.0
 
  - role: database
 
    db_name: wsgi_{{ testsite_domain_underscores }}
 
    db_password: wsgi_{{ testsite_domain_underscores }}
 
\ No newline at end of file
testsite/playbooks/roles/wsgihello2/tasks/main.yml
Show inline comments
 
new file 100644
 
---
 

	
 
- name: Create directory for storing code
 
  file: dest="/var/www/wsgireq.{{ testsite_domain }}/code/" state=directory
 
        owner="admin-wsgireq_{{ testsite_domain_underscores }}" group="web-wsgireq_{{ testsite_domain_underscores }}" mode=2750
 

	
 
- name: Deploy requirements and its source for upgrade checks
 
  copy: src="{{ item }}" dest="/etc/pip_check_requirements_upgrades/{{ item }}"
 
        owner="root" group="pipreqcheck" mode=640
 
  with_items:
 
    - requirements.in
 
    - requirements.txt
 

	
 
- name: Deploy requirements
 
  copy: src="{{ item }}" dest="/var/www/wsgireq.{{ testsite_domain }}/code/"
 
        owner="admin-wsgireq_{{ testsite_domain_underscores }}" group="web-wsgireq_{{ testsite_domain_underscores }}" mode=640
 
  with_items:
 
    - requirements.txt
 

	
 
- name: Install latest version of pip
 
  become_user: "admin-wsgireq_{{ testsite_domain_underscores }}"
 
  pip: name=pip state=latest virtualenv="/var/www/wsgireq.{{ testsite_domain }}/virtualenv"
 

	
 
- name: Deploy pip-tools
 
  become_user: "admin-wsgireq_{{ testsite_domain_underscores }}"
 
  pip: name=pip-tools state=present virtualenv="/var/www/wsgireq.{{ testsite_domain }}/virtualenv"
 

	
 
- name: Synchronise virtual environment with requirements file
 
  become_user: "admin-wsgireq_{{ testsite_domain_underscores }}"
 
  command: "'/var/www/wsgireq.{{ testsite_domain }}/virtualenv/bin/exec' pip-sync ~/code/requirements.txt ~/.wsgi_requirements.txt"
 
  register: pip_sync_result
 
  changed_when: "pip_sync_result.stdout != 'Everything up-to-date'"
 
  notify:
 
    - Restart website wsgireq.{{ testsite_domain }}
 

	
 
- 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
testsite/playbooks/tls.yml
Show inline comments
 
@@ -21,6 +21,9 @@
 
      - hostname: wsgi
 
        service: https
 
        name: WSGI Hello World
 
      - hostname: wsgireq
 
        service: https
 
        name: WSGI Hello World
 
      - hostname: xmpp
 
        service: xmpp
 
        name: XMPP
testsite/playbooks/web.yml
Show inline comments
 
@@ -11,3 +11,4 @@
 
    - web_server
 
    - phpinfo
 
    - wsgihello
 
    - wsgihello2
 
\ No newline at end of file
0 comments (0 inline, 0 general)