This commit is contained in:
decentral1se
2022-05-30 09:31:11 +02:00
commit a66d7d6e8d
28 changed files with 1011 additions and 0 deletions

View File

@ -0,0 +1,2 @@
FROM {{ item.image }}
RUN /bin/sh -c 'apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash'

View File

@ -0,0 +1,41 @@
---
- name: Setup
hosts: localhost
connection: local
gather_facts: False
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
vars:
molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
molecule_ephemeral_directory: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}"
molecule_scenario_directory: "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}"
molecule_yml: "{{ lookup('file', molecule_file) | from_yaml }}"
tasks:
- name: Create Dockerfiles from image names
template:
src: "{{ molecule_scenario_directory }}/Dockerfile.j2"
dest: "{{ molecule_ephemeral_directory }}/Dockerfile_{{ item.image | regex_replace('[^a-zA-Z0-9_]', '_') }}"
with_items: "{{ molecule_yml.platforms }}"
register: platforms
- name: Build an Ansible compatible image
docker_image:
path: "{{ molecule_ephemeral_directory }}"
name: "molecule_local/{{ item.item.image }}"
dockerfile: "{{ item.item.dockerfile | default(item.invocation.module_args.dest) }}"
force: "{{ item.item.force | default(True) }}"
with_items: "{{ platforms.results }}"
when: platforms.changed
- name: Create molecule instance(s)
docker_container:
name: "{{ item.name }}"
hostname: "{{ item.name }}"
image: "molecule_local/{{ item.image }}"
state: started
recreate: False
log_driver: json-file
command: "{{ item.command | default('sleep infinity') }}"
privileged: "{{ item.privileged | default(omit) }}"
volumes: "{{ item.volumes | default(omit) }}"
capabilities: "{{ item.capabilities | default(omit) }}"
with_items: "{{ molecule_yml.platforms }}"

View File

@ -0,0 +1,16 @@
---
- name: Teardown
hosts: localhost
connection: local
gather_facts: False
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
vars:
molecule_file: "{{ lookup('env','MOLECULE_FILE') }}"
molecule_yml: "{{ lookup('file', molecule_file) | from_yaml }}"
tasks:
- name: Destroy molecule instance(s)
docker_container:
name: "{{ item.name }}"
state: absent
force_kill: "{{ item.force_kill | default(True) }}"
with_items: "{{ molecule_yml.platforms }}"

View File

@ -0,0 +1,45 @@
---
dependency:
name: gilt
driver:
name: docker
lint:
name: yamllint
platforms:
- name: container
image: debian:stretch
privileged: true
provisioner:
name: ansible
lint:
name: ansible-lint
connection_options:
ansible_ssh_user: 'root'
ansible_ssh_common_args: -o ServerAliveInterval=30 -o ControlMaster=auto -o ControlPersist=60s
scenario:
name: default
test_sequence:
- dependency
- lint
- cleanup
- destroy
- syntax
- create
- prepare
- converge
# no idempotence for the moment
# - idempotence
- side_effect
- verify
- cleanup
- destroy
verifier:
name: testinfra
lint:
name: flake8

View File

@ -0,0 +1,11 @@
---
- name: Converge
hosts: all
gather_facts: True
become: true
roles:
- role: autonomic.discourse.email
vars:
hostname: forum.example.com
root_email_forward: nobody@example.com
DISCOURSE_API_KEY: foobar

View File

@ -0,0 +1,30 @@
---
- name: Prepare
hosts: all
gather_facts: True
become: True
roles:
- role: geerlingguy.docker
tasks:
- name: Install python for Ansible
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal python-zipstream)
become: true
changed_when: false
- name: Install Ansible Python packages
apt:
package:
- python-setuptools
- python-pip
become: true
- name: Install python-docker
pip:
name: docker
- name: Create dummy Discourse container
docker_container:
name: app
image: alpine
state: started
privileged: true

View File

@ -0,0 +1,2 @@
---
- geerlingguy.docker

View File

@ -0,0 +1,9 @@
---
file:
/etc/mail-receiver-environment.json:
exists: true
package:
postfix:
installed: true