Changeset - 19b29f0c7e7e
[Not reviewed]
0 10 2
Branko Majic (branko) - 6 years ago 2018-05-31 23:31:12
branko@majic.rs
MAR-129: Updated backup role for new Ansible and Molecule:

- Fixed linting errors.
- Include top-level linting configuration in tests.
- Moved variables from test playbook into group_vars.
- Updated how the hosts are referenced in tests.
12 files changed with 54 insertions and 48 deletions:
0 comments (0 inline, 0 general)
roles/backup/handlers/main.yml
Show inline comments
 
@@ -7,4 +7,4 @@
 
    owner: root
 
    group: root
 
    mode: 0600
 
    backup: yes
 
    backup: true
roles/backup/meta/main.yml
Show inline comments
 
---
 

	
 
allow_duplicates: yes
 
allow_duplicates: true
 

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

	
 
backup_patterns_filename: "test"
 

	
 
# backup_client role parameters.
 
backup_encryption_key: "{{ lookup('file', 'tests/data/gnupg/parameters-mandatory.asc') }}"
 
backup_server: 10.31.127.10
 
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-mandatory' ) }}"
roles/backup/molecule/default/group_vars/parameters-optional.yml
Show inline comments
 
new file 100644
 
---
 

	
 
backup_patterns_filename: "test"
 
backup_patterns:
 
  - /etc/hosts
 
  - /etc/ethers
 
  - /var/log
 

	
 
# backup_client role parameters.
 
backup_encryption_key: "{{ lookup('file', 'tests/data/gnupg/parameters-optional.asc') }}"
 
backup_server: 10.31.127.10
 
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-mandatory' ) }}"
roles/backup/molecule/default/molecule.yml
Show inline comments
 
@@ -9,6 +9,8 @@ driver:
 

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

	
 
platforms:
 

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

	
 
- hosts: parameters-mandatory
 
  become: yes
 
- hosts: parameters-mandatory,parameters-optional
 
  become: true
 
  roles:
 
    - role: backup
 
      backup_patterns_filename: "test"
 
  vars:
 
    # Required for backup_client role which is part of meta dependencies.
 
    backup_encryption_key: "{{ lookup('file', 'tests/data/gnupg/parameters-mandatory.asc') }}"
 
    backup_server: 10.31.127.10
 
    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-mandatory' ) }}"
 

	
 

	
 
- hosts: parameters-optional
 
  become: yes
 
  roles:
 
    - role: backup
 
      backup_patterns_filename: "test"
 
      backup_patterns:
 
        - /etc/hosts
 
        - /etc/ethers
 
        - /var/log
 
  vars:
 
    # Required for backup_client role which is part of meta dependencies.
 
    backup_encryption_key: "{{ lookup('file', 'tests/data/gnupg/parameters-optional.asc') }}"
 
    backup_server: 10.31.127.10
 
    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-mandatory' ) }}"
 
    - backup
roles/backup/molecule/default/prepare.yml
Show inline comments
 
@@ -2,18 +2,18 @@
 

	
 
- 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
roles/backup/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_backup_patterns_file(host):
roles/backup/molecule/default/tests/test_parameters_mandatory.py
Show inline comments
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

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

	
 

	
 
def test_backup_patterns_content(host):
roles/backup/molecule/default/tests/test_parameters_optional.py
Show inline comments
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

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

	
 

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