Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added molecular default test szenario and configured travis-ci #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
*.iml
molecule/**/.molecule/
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---

sudo: required
language: python
services:
- docker
before_install:
- sudo apt-get update
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
install:
- pip install molecule
- pip install docker-py
script:
- molecule test
17 changes: 17 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends: default

rules:
braces:
max-spaces-inside: 1
level: warning
brackets:
max-spaces-inside: 1
level: warning
line-length: disable
truthy: disable
empty-lines:
level: warning
indentation:
level: warning
indent-sequences: consistent
new-line-at-end-of-file: disable
7 changes: 7 additions & 0 deletions molecule/default/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM {{ item.image }}

RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates cron && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python python-devel python2-dnf bash cron && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash cron && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml cron && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates cron; fi
46 changes: 46 additions & 0 deletions molecule/default/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
*******
Install
*******

This set of playbooks have specific dependencies on Ansible due to the modules
being used.

Requirements
============

* Ansible 2.2
* Docker Engine
* docker-py

Install OS dependencies on CentOS 7

.. code-block:: bash

$ sudo yum install -y epel-release
$ sudo yum install -y gcc python-pip python-devel openssl-devel
# If installing Molecule from source.
$ sudo yum install libffi-devel git

Install OS dependencies on Ubuntu 16.x

.. code-block:: bash

$ sudo apt-get update
$ sudo apt-get install -y python-pip libssl-dev docker-engine
# If installing Molecule from source.
$ sudo apt-get install -y libffi-dev git

Install OS dependencies on Mac OS

.. code-block:: bash

$ brew install python
$ brew install git

Install using pip:

.. code-block:: bash

$ sudo pip install ansible
$ sudo pip install docker-py
$ sudo pip install molecule --pre
47 changes: 47 additions & 0 deletions molecule/default/create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
- name: Create
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: Discover local Docker images
docker_image_facts:
name: "molecule_local/{{ item.item.name }}"
with_items: "{{ platforms.results }}"
register: docker_images

- 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 or docker_images.results | map(attribute='images') | select('equalto', []) | list | count >= 0

- name: Create molecule instance(s)
docker_container:
name: "{{ item.name }}"
hostname: "{{ item.name }}"
image: "molecule_local/{{ item.image }}"
state: started
recreate: False
log_driver: syslog
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 }}"
16 changes: 16 additions & 0 deletions molecule/default/destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Destroy
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 }}"
64 changes: 64 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: ubuntu-16.04
image: ubuntu
image_version: '16.04'
command: /lib/systemd/systemd
privileged: true
# - name: centos-7
# image: centos
# image_version: '7'
# command: /lib/systemd/systemd
# privileged: true
# - name: centos-8
# image: centos
# image_version: '8'
# command: /lib/systemd/systemd
# privileged: true
# - name: opensuse-13.2
# image: opensuse
# image_version: '13.2'
# command: /lib/systemd/systemd
# privileged: true
# - name: opensuse-42.3
# image: opensuse
# image_version: '42.3'
# command: /lib/systemd/systemd
# privileged: true
provisioner:
name: ansible
lint:
name: ansible-lint
enabled: False

scenario:
name: default
check_sequence:
- destroy
- create
- converge
- check
- destroy
converge_sequence:
- create
- converge
destroy_sequence:
- destroy
test_sequence:
- destroy
- dependency
- create
- converge
- lint
- verify
- destroy
verifier:
name: testinfra
lint:
name: flake8
6 changes: 6 additions & 0 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Converge
hosts: all
roles:
- role: ansiblebit.oracle-java
- role: ansible-nexus3-oss
3 changes: 3 additions & 0 deletions molecule/default/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

- src: ansiblebit.oracle-java
14 changes: 14 additions & 0 deletions molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_hosts_file(host):
f = host.file('/etc/hosts')

assert f.exists
assert f.user == 'root'
assert f.group == 'root'
Binary file added molecule/default/tests/test_default.pyc
Binary file not shown.