Changeset - 14eb78a4f466
[Not reviewed]
0 11 0
Branko Majic (branko) - 7 years ago 2018-06-03 10:19:04
branko@majic.rs
MAR-129: Updated php_website role for Ansible 2.5.x and new Molecule:

- Include global linting configuration file in tests.
- Fixed linting issues.
- Fix deprecation warnings from Ansible (for apt module and
state=installed).
- Updated how the hosts are being referenced within tests.
11 files changed with 29 insertions and 25 deletions:
0 comments (0 inline, 0 general)
roles/php_website/defaults/main.yml
Show inline comments
 
---
 

	
 
additional_nginx_config: {}
 
deny_files_regex: []
 
enforce_https: True
 
enforce_https: true
 
index: index.php
 
packages: []
 
php_file_regex: \.php$
 
php_rewrite_urls: []
 
rewrites: []
 
https_tls_certificate: "{{ lookup('file', tls_certificate_dir + '/' + fqdn + '_https.pem') }}"
roles/php_website/meta/main.yml
Show inline comments
 
---
 

	
 
allow_duplicates: yes
 
allow_duplicates: true
 

	
 
dependencies:
 
  - common
 
  - web_server
roles/php_website/molecule/default/create.yml
Show inline comments
 
---
 
- 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') }}"
 
    molecule_instance_config: "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}"
 
    molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}"
 
  tasks:
roles/php_website/molecule/default/destroy.yml
Show inline comments
 
---
 

	
 
- 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') }}"
 
    molecule_instance_config: "{{ lookup('env',' MOLECULE_INSTANCE_CONFIG') }}"
 
    molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}"
 
  tasks:
roles/php_website/molecule/default/molecule.yml
Show inline comments
 
@@ -6,12 +6,14 @@ driver:
 
  name: vagrant
 
  provider:
 
    name: virtualbox
 

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

	
 
platforms:
 

	
 
  - name: php-website-jessie64
 
    groups:
 
      - parameters-mandatory
roles/php_website/molecule/default/playbook.yml
Show inline comments
 
---
 

	
 
- hosts: all
 
  become: yes
 
  become: true
 
  vars:
 
    # common
 
    ca_certificates:
 
      testca: "{{ lookup('file', 'tests/data/x509/ca.cert.pem') }}"
 

	
 
    # web_server
 
@@ -26,13 +26,13 @@
 
      additional_nginx_config:
 
        - comment: Custom missing page.
 
          value: error_page 404 /404.myphp;
 
      admin_uid: 5000
 
      deny_files_regex:
 
        - '^/secretfile.txt'
 
      enforce_https: no
 
      enforce_https: false
 
      environment_indicator:
 
        background_colour: "#ff0000"
 
        text_colour: "#00ff00"
 
        text: "parameters-optional"
 
      fqdn: parameters-optional.local
 
      index: myindex.php
 
@@ -50,13 +50,13 @@
 
        - php5-json
 
        - libmariadb-client-lgpl-dev-compat
 
      uid: 5001
 
      website_mail_recipients: user
 

	
 
- hosts: all
 
  become: yes
 
  become: true
 
  tasks:
 
    # parameters-mandatory application
 
    - name: Set-up directory where PHP files are hosted at
 
      file:
 
        path: /var/www/parameters-mandatory/htdocs
 
        state: directory
roles/php_website/molecule/default/prepare.yml
Show inline comments
 
---
 

	
 
- 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: all
 
  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:
 
        dest: /etc/hosts
 
        line: "{{ ansible_eth0.ipv4.address }} parameters-mandatory parameters-optional.local php-website"
 

	
 
    - 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:
 
        name: user
 
        state: present
 

	
roles/php_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'])
roles/php_website/molecule/default/tests/test_parameters_mandatory.py
Show inline comments
 
import os
 
import re
 
import time
 

	
 

	
 
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):
 
    """
 
    Tests if website group has been created correctly.
 
    """
roles/php_website/molecule/default/tests/test_parameters_optional.py
Show inline comments
 
import os
 
import re
 
import time
 

	
 

	
 
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):
 
    """
 
    Tests if website group has been created correctly.
 
    """
roles/php_website/tasks/main.yml
Show inline comments
 
@@ -9,13 +9,13 @@
 
- name: Create PHP website admin user
 
  user:
 
    name: "{{ admin }}"
 
    uid: "{{ admin_uid | default(omit) }}"
 
    group: "{{ user }}"
 
    shell: /bin/bash
 
    createhome: yes
 
    createhome: true
 
    home: "{{ home }}"
 
    state: present
 

	
 
- name: Set-up directory for storing user profile configuration files
 
  file:
 
    path: "{{ home }}/.profile.d"
 
@@ -27,14 +27,14 @@
 
- name: Create PHP website user
 
  user:
 
    name: "{{ user }}"
 
    uid: "{{ uid | default(omit) }}"
 
    group: "{{ user }}"
 
    comment: "umask=0007"
 
    system: yes
 
    createhome: no
 
    system: true
 
    createhome: false
 
    state: present
 
    home: "{{ home }}"
 

	
 
- name: Add nginx user to website group
 
  user:
 
    name: "www-data"
 
@@ -53,13 +53,13 @@
 
    group: "{{ user }}"
 
    mode: 0640
 

	
 
- name: Install extra packages for website
 
  apt:
 
    name: "{{ item }}"
 
    state: installed
 
    state: present
 
  with_items: "{{ packages }}"
 

	
 
- name: Set-up MariaDB mysql_config symbolic link for compatibility (workaround for Debian bug 766996)
 
  file:
 
    src: "/usr/bin/mariadb_config"
 
    dest: "/usr/bin/mysql_config"
0 comments (0 inline, 0 general)