Changeset - 48a901602e77
[Not reviewed]
0 9 2
Branko Majic (branko) - 6 years ago 2018-06-03 11:46:47
branko@majic.rs
MAR-129: Updated bootstrap role for Ansible 2.5.x and new Molecule:

- Include top-level lint configuration file.
- Fixed linting errors.
- Moved test playbook parameters into group_vars.
- Fixed Ansible deprecation warnings.
- Updated how the hosts are referenced in tests.
11 files changed with 26 insertions and 23 deletions:
0 comments (0 inline, 0 general)
roles/bootstrap/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/bootstrap/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/bootstrap/molecule/default/group_vars/parameters-mandatory.yml
Show inline comments
 
new file 100644
 
---
roles/bootstrap/molecule/default/group_vars/parameters-optional.yml
Show inline comments
 
new file 100644
 
---
 

	
 
ansible_key: "{{ lookup('file', 'tests/data/ansible_key.pub') }}"
roles/bootstrap/molecule/default/molecule.yml
Show inline comments
 
@@ -9,6 +9,8 @@ driver:
 

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

	
 
platforms:
 

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

	
 
- hosts: parameters-mandatory
 
  become: yes
 
- hosts: parameters-mandatory,parameters-optional
 
  become: true
 
  roles:
 
    - role: bootstrap
 

	
 
- hosts: parameters-optional
 
  become: yes
 
  roles:
 
    - role: bootstrap
 
      ansible_key: "{{ lookup('file', 'tests/data/ansible_key.pub') }}"
 
    - bootstrap
roles/bootstrap/molecule/default/prepare.yml
Show inline comments
 
@@ -2,16 +2,16 @@
 

	
 
- 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
 

	
 
# Put Ansible key into root's authorized_keys to test its removal.
 
- hosts: parameters-mandatory
 
  become: yes
 
  become: true
 
  tasks:
 

	
 
    - name: Deploy authorized_keys to mimic set-up via preseed file
 
@@ -21,7 +21,7 @@
 

	
 
# Put Ansible key into root's authorized_keys to test its removal.
 
- hosts: parameters-optional
 
  become: yes
 
  become: true
 
  tasks:
 

	
 
    - name: Deploy authorized_keys to mimic set-up via preseed file
roles/bootstrap/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_installed_packages(host):
roles/bootstrap/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_authorized_keys(host):
roles/bootstrap/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_authorized_keys(host):
roles/bootstrap/tasks/main.yml
Show inline comments
 
@@ -3,17 +3,17 @@
 
- name: Install sudo
 
  apt:
 
    name: sudo
 
    state: installed
 
    state: present
 

	
 
- name: Set-up the Ansible group
 
  group:
 
    name: ansible
 
    system: yes
 
    system: true
 

	
 
- name: Set-up the Ansible user
 
  user:
 
    name: ansible
 
    system: yes
 
    system: true
 
    group: ansible
 
    shell: /bin/bash
 

	
0 comments (0 inline, 0 general)