Changeset - fdba88395073
[Not reviewed]
0 9 2
Branko Majic (branko) - 6 years ago 2018-05-27 20:55:39
branko@majic.rs
MAR-129: Updated database role for new Molecule and Ansible versions:

- Fixed linting issues.
- Moved test variables into group_vars.
- Renamed the server which effectively tests the optional
parameters (mainly the backup).
- Updated tests to use correct mechanism for obtaining the list of
hosts on top of which the tests should be run.
11 files changed with 54 insertions and 46 deletions:
0 comments (0 inline, 0 general)
roles/database/defaults/main.yml
Show inline comments
 
---
 

	
 
enable_backup: False
 
enable_backup: false
roles/database/meta/main.yml
Show inline comments
 
---
 

	
 
allow_duplicates: yes
 
allow_duplicates: true
 

	
 
dependencies:
 
  - database_server
roles/database/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/database/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/database/molecule/default/group_vars/parameters-mandatory.yml
Show inline comments
 
new file 100644
 
---
 

	
 
db_name: testdb
 
db_password: testdbpassword
 

	
 
# database_server role
 
db_root_password: "root_password"
roles/database/molecule/default/group_vars/parameters-optional.yml
Show inline comments
 
new file 100644
 
---
 

	
 
db_name: testdb
 
db_password: testdbpassword
 
enable_backup: true
 

	
 
# database_server
 
db_root_password: "root_password"
 

	
 
# backup_client
 
backup_client_username: "bak-localhost"
 
backup_encryption_key: "{{ lookup('file', 'tests/data/gnupg/parameters-optional.asc') }}"
 
backup_server: localhost
 
backup_server_host_ssh_public_keys:
 
  - "{{ lookup('file', 'tests/data/ssh/server_dsa.pub') }}"
 
  - "{{ lookup('file', 'tests/data/ssh/server_rsa.pub') }}"
 
  - "{{ lookup('file', 'tests/data/ssh/server_ed25519.pub') }}"
 
  - "{{ lookup('file', 'tests/data/ssh/server_ecdsa.pub') }}"
 
backup_ssh_key: "{{ lookup('file', 'tests/data/ssh/parameters-optional' ) }}"
roles/database/molecule/default/molecule.yml
Show inline comments
 
@@ -9,6 +9,8 @@ driver:
 

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

	
 
platforms:
 

	
 
@@ -19,9 +21,10 @@ platforms:
 
    memory: 256
 
    cpus: 1
 

	
 
  - name: backup-jessie64
 
  - name: parameters-optional-jessie64
 
    groups:
 
      - backup
 
      - parameters-optional
 
      - backup-server
 
    box: debian/contrib-jessie64
 
    memory: 512
 
    cpus: 1
roles/database/molecule/default/playbook.yml
Show inline comments
 
---
 

	
 

	
 
- hosts: parameters-mandatory
 
  become: yes
 
- hosts: parameters-mandatory,parameters-optional
 
  become: true
 
  roles:
 
    - role: database
 
      db_name: testdb
 
      db_password: testdbpassword
 

	
 
      # database_server role
 
      db_root_password: "root_password"
 

	
 
- hosts: backup
 
  become: yes
 
  roles:
 
    - role: database
 
      db_name: testdb
 
      db_password: testdbpassword
 
      enable_backup: yes
 

	
 
      # database_server
 
      db_root_password: "root_password"
 

	
 
      # backup_client
 
      backup_client_username: "bak-localhost"
 
      backup_encryption_key: "{{ lookup('file', 'tests/data/gnupg/parameters-optional.asc') }}"
 
      backup_server: localhost
 
      backup_server_host_ssh_public_keys:
 
        - "{{ lookup('file', 'tests/data/ssh/server_dsa.pub') }}"
 
        - "{{ lookup('file', 'tests/data/ssh/server_rsa.pub') }}"
 
        - "{{ lookup('file', 'tests/data/ssh/server_ed25519.pub') }}"
 
        - "{{ lookup('file', 'tests/data/ssh/server_ecdsa.pub') }}"
 
      backup_ssh_key: "{{ lookup('file', 'tests/data/ssh/parameters-optional' ) }}"
 
    - database
roles/database/molecule/default/prepare.yml
Show inline comments
 
@@ -2,24 +2,24 @@
 

	
 
- 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
 

	
 
- hosts: backup
 
  become: yes
 
- hosts: backup-server
 
  become: true
 
  roles:
 
    - role: backup_server
 
      backup_host_ssh_private_keys:
roles/database/molecule/default/tests/test_backup.py
Show inline comments
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

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

	
 

	
 
def test_backup_directories(host):
roles/database/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(['parameters-mandatory', 'parameters-optional'])
 

	
 

	
 
def test_database_created(host):
0 comments (0 inline, 0 general)