Changeset - b5ed796b566a
[Not reviewed]
0 13 0
Branko Majic (branko) - 6 years ago 2018-06-03 10:32:03
branko@majic.rs
MAR-129: Updated wsgi_website role for Ansible 2.5.x and new Molecule:

- Include top-level linting configuration in test configuration file.
- Fixed linting errors.
- Updated Ansible deprecation warnings related to use of
state=installed with apt module.
- Updated how hosts are being referenced in tests.
- Rename the 'ss' utility in order to properly test socket
connectivity as a workaround for Testinfra bug.
13 files changed with 43 insertions and 33 deletions:
0 comments (0 inline, 0 general)
roles/wsgi_website/defaults/main.yml
Show inline comments
 
---
 

	
 
additional_nginx_config: {}
 
enforce_https: True
 
enforce_https: true
 
packages: []
 
rewrites: []
 
static_locations: []
 
use_paste: False
 
use_paste: false
 
virtualenv_packages: []
 
environment_variables: {}
 
https_tls_certificate: "{{ lookup('file', tls_certificate_dir + '/' + fqdn + '_https.pem') }}"
roles/wsgi_website/meta/main.yml
Show inline comments
 
---
 

	
 
allow_duplicates: yes
 
allow_duplicates: true
 

	
 
dependencies:
 
  - common
roles/wsgi_website/molecule/default/create.yml
Show inline comments
 
@@ -2,7 +2,7 @@
 
- name: Create
 
  hosts: localhost
 
  connection: local
 
  gather_facts: False
 
  gather_facts: false
 
  no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
 
  vars:
 
    molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
roles/wsgi_website/molecule/default/destroy.yml
Show inline comments
 
@@ -3,7 +3,7 @@
 
- name: Destroy
 
  hosts: localhost
 
  connection: local
 
  gather_facts: False
 
  gather_facts: false
 
  no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
 
  vars:
 
    molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
roles/wsgi_website/molecule/default/molecule.yml
Show inline comments
 
@@ -9,6 +9,8 @@ driver:
 

	
 
lint:
 
  name: yamllint
 
  options:
 
    config-file: ../../.yamllint.yml
 

	
 
platforms:
 

	
roles/wsgi_website/molecule/default/playbook.yml
Show inline comments
 
---
 

	
 
- hosts: wsgi-website
 
  become: yes
 
  become: true
 
  vars:
 
    # common
 
    ca_certificates:
 
@@ -26,7 +26,7 @@
 
        - comment: Custom missing page.
 
          value: error_page 404 /my/own/error/page;
 
      admin_uid: 5000
 
      enforce_https: no
 
      enforce_https: false
 
      environment_indicator:
 
        background_colour: "#ff0000"
 
        text_colour: "#00ff00"
 
@@ -49,7 +49,7 @@
 
        - /static/
 
        - /media/
 
      uid: 5001
 
      use_paste: no
 
      use_paste: false
 
      virtualenv_packages:
 
        - dnspython==1.15.0,<1.20.0
 
        - ptpython==0.41
 
@@ -60,7 +60,7 @@
 

	
 
    - role: wsgi_website
 
      fqdn: parameters-paste-req
 
      use_paste: yes
 
      use_paste: true
 
      virtualenv_packages:
 
        - click==6.7
 
        - Flask==0.12.2
 
@@ -80,7 +80,7 @@
 
      https_tls_key: "{{ lookup('file', 'tests/data/x509/parameters-paste-req_https.key.pem') }}"
 

	
 
- hosts: wsgi-website
 
  become: yes
 
  become: true
 
  tasks:
 
    # parameters-mandatory application
 
    - name: Set-up directories where application files are hosted at
roles/wsgi_website/molecule/default/prepare.yml
Show inline comments
 
@@ -2,21 +2,21 @@
 

	
 
- name: Prepare
 
  hosts: all
 
  gather_facts: False
 
  gather_facts: false
 
  tasks:
 
    - name: Install python for Ansible
 
      raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
 
      become: True
 
      changed_when: False
 
      become: true
 
      changed_when: false
 

	
 
- hosts: wsgi-website
 
  become: yes
 
  become: true
 
  tasks:
 

	
 
    - name: Update all caches to avoid errors due to missing remote archives
 
      apt:
 
        update_cache: yes
 
      changed_when: False
 
        update_cache: true
 
      changed_when: false
 

	
 
    - name: Set-up /etc/hosts entries
 
      lineinfile:
 
@@ -26,17 +26,17 @@
 
    - name: Install curl for testing redirects and webpage content
 
      apt:
 
        name: curl
 
        state: installed
 
        state: present
 

	
 
    - name: Install swaks for testing mail forwarding
 
      apt:
 
        name: swaks
 
        state: installed
 
        state: present
 

	
 
    - name: Install Postfix for testing mail forwarding (Exim4 not covered)
 
      apt:
 
        name: postfix
 
        state: installed
 
        state: present
 

	
 
    - name: Set-up group for an additional user
 
      group:
 
@@ -48,3 +48,6 @@
 
        name: user
 
        group: user
 
        shell: /bin/bash
 

	
 
    - name: Rename the ss utility (see https://github.com/philpep/testinfra/pull/320)
 
      command: "mv /bin/ss /bin/ss.bak"
roles/wsgi_website/molecule/default/tests/test_default.py
Show inline comments
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory.yml').get_hosts('all')
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['all'])
 

	
 

	
 
def test_hosts_file(host):
roles/wsgi_website/molecule/default/tests/test_parameters_mandatory.py
Show inline comments
 
import os
 
import re
 
import time
 

	
 
@@ -5,7 +6,7 @@ import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory.yml').get_hosts('all')
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['all'])
 

	
 

	
 
def test_website_group(host):
roles/wsgi_website/molecule/default/tests/test_parameters_optional.py
Show inline comments
 
import os
 
import re
 
import time
 

	
 
@@ -5,7 +6,7 @@ import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory.yml').get_hosts('all')
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['all'])
 

	
 

	
 
def test_website_group(host):
roles/wsgi_website/molecule/default/tests/test_parameters_paste_req.py
Show inline comments
 
import os
 
import re
 
import time
 

	
 
@@ -5,7 +6,7 @@ import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    '.molecule/ansible_inventory.yml').get_hosts('all')
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['all'])
 

	
 

	
 
def test_website_group(host):
roles/wsgi_website/tasks/main.yml
Show inline comments
 
@@ -12,7 +12,7 @@
 
    uid: "{{ admin_uid | default(omit) }}"
 
    group: "{{ user }}"
 
    shell: /bin/bash
 
    createhome: yes
 
    createhome: true
 
    home: "{{ home }}"
 
    state: present
 

	
 
@@ -46,8 +46,8 @@
 
    uid: "{{ uid | default(omit) }}"
 
    group: "{{ user }}"
 
    comment: "umask=0007"
 
    system: yes
 
    createhome: no
 
    system: true
 
    createhome: false
 
    state: present
 
    home: "{{ home }}"
 

	
 
@@ -55,7 +55,7 @@
 
  user:
 
    name: www-data
 
    groups: "{{ user }}"
 
    append: yes
 
    append: true
 
  notify:
 
    - Restart nginx
 

	
 
@@ -97,7 +97,7 @@
 
  command: '/usr/bin/virtualenv --prompt "({{ fqdn }})" "{{ home }}/virtualenv"'
 
  args:
 
    creates: "{{ home }}/virtualenv/bin/activate"
 
  become: yes
 
  become: true
 
  become_user: "{{ admin }}"
 
  tags:
 
    # [ANSIBLE0012] Commands should not change things if nothing needs doing
 
@@ -122,7 +122,7 @@
 
    mode: 0750
 

	
 
- name: Install WSGI server
 
  become: yes
 
  become: true
 
  become_user: "{{ admin }}"
 
  pip:
 
    name: "{{ item.package }}"
 
@@ -143,7 +143,7 @@
 
  when: "wsgi_requirements"
 

	
 
- name: Install additional packages in Python virtual environment
 
  become: yes
 
  become: true
 
  become_user: "{{ admin }}"
 
  pip:
 
    name: "{{ virtualenv_packages }}"
 
@@ -180,7 +180,7 @@
 
- name: Enable the website service
 
  service:
 
    name: "{{ fqdn }}"
 
    enabled: yes
 
    enabled: true
 
    state: started
 

	
 
- name: Create directory where static files can be served from
roles/wsgi_website/tasks/requirements.yml
Show inline comments
 
@@ -20,7 +20,7 @@
 
    - wsgi_requirements.txt
 

	
 
- name: Deploy Gunicorn requirements file for installation purposes
 
  become: yes
 
  become: true
 
  become_user: "{{ admin }}"
 
  template:
 
    src: "wsgi_requirements.txt.j2"
 
@@ -30,7 +30,7 @@
 
    mode: 0640
 

	
 
- name: Install Gunicorn via requirements file
 
  become: yes
 
  become: true
 
  become_user: "{{ admin }}"
 
  pip:
 
    requirements: "{{ home }}/.wsgi_requirements.txt"
0 comments (0 inline, 0 general)