This repository has been archived by the owner on Oct 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
872 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
molecule/default/.molecule/ | ||
molecule/default/.cache/ | ||
*.pyc | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
extends: default | ||
|
||
rules: | ||
braces: | ||
max-spaces-inside: 1 | ||
level: error | ||
brackets: | ||
max-spaces-inside: 1 | ||
level: error | ||
line-length: disable | ||
truthy: disable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[[source]] | ||
|
||
url = "https://pypi.python.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
|
||
[packages] | ||
|
||
molecule = "*" | ||
ansible = "==2.3.3.0" | ||
enum = "*" | ||
"flake8" = "*" | ||
docker = "*" | ||
pbr = "*" | ||
funcsigs = "*" | ||
"backports.functools-lru-cache" = "*" | ||
configparser = "*" | ||
"enum34" = "*" | ||
ipaddress = "*" | ||
docker-py = "*" | ||
"backports.ssl-match-hostname" = "*" | ||
python-vagrant = "*" | ||
|
||
|
||
[dev-packages] | ||
|
||
|
||
|
||
[requires] | ||
|
||
python_version = "2.7" |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Molecule managed | ||
|
||
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 && apt-get clean; \ | ||
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ | ||
elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && 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 && zypper clean -a; \ | ||
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
******* | ||
Install | ||
******* | ||
|
||
Requirements | ||
============ | ||
|
||
* Docker Engine | ||
* docker-py | ||
|
||
Install | ||
======= | ||
|
||
.. code-block:: bash | ||
$ sudo pip install docker-py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
- 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) | molecule_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: json-file | ||
command: "{{ item.command | default('bash -c \"while true; do sleep 10000; done\"') }}" | ||
privileged: "{{ item.privileged | default(omit) }}" | ||
volumes: "{{ item.volumes | default(omit) }}" | ||
capabilities: "{{ item.capabilities | default(omit) }}" | ||
ports: "{{ item.exposed_ports | default(omit) }}" | ||
ulimits: "{{ item.ulimits | default(omit) }}" | ||
register: server | ||
with_items: "{{ molecule_yml.platforms }}" | ||
async: 7200 | ||
poll: 0 | ||
|
||
- name: Wait for instance(s) creation to complete | ||
async_status: | ||
jid: "{{ item.ansible_job_id }}" | ||
register: docker_jobs | ||
until: docker_jobs.finished | ||
retries: 300 | ||
with_items: "{{ server.results }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
- 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) | molecule_from_yaml }}" | ||
tasks: | ||
- name: Destroy molecule instance(s) | ||
docker_container: | ||
name: "{{ item.name }}" | ||
state: absent | ||
force_kill: "{{ item.force_kill | default(true) }}" | ||
register: server | ||
with_items: "{{ molecule_yml.platforms }}" | ||
async: 7200 | ||
poll: 0 | ||
|
||
- name: Wait for instance(s) deletion to complete | ||
async_status: | ||
jid: "{{ item.ansible_job_id }}" | ||
register: docker_jobs | ||
until: docker_jobs.finished | ||
retries: 300 | ||
with_items: "{{ server.results }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
dependency: | ||
name: galaxy | ||
driver: | ||
name: docker | ||
lint: | ||
name: yamllint | ||
platforms: | ||
- name: instance | ||
image: ubuntu:16.04 | ||
provisioner: | ||
name: ansible | ||
lint: | ||
name: ansible-lint | ||
scenario: | ||
name: default | ||
verifier: | ||
name: testinfra | ||
lint: | ||
name: flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
roles: | ||
- role: ansible-role-consul |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
- name: Prepare | ||
hosts: all | ||
gather_facts: false | ||
tasks: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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' | ||
|
||
|
||
def test_consul_configuration(host): | ||
host.run_expect([0], 'consul validate /etc/consul.d') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,6 @@ | |
apt: | ||
name: dnsmasq | ||
state: present | ||
update_cache: yes | ||
cache_valid_time: 3600 | ||
tags: | ||
- dnsmasq | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
{ | ||
"server": false, | ||
"ui": false, | ||
|
||
"data_dir": "{{ consul_data_dir }}", | ||
"pid_file": "{{ consul_data_dir }}/consul.pid", | ||
"datacenter": "{{ consul_datacenter }}", | ||
"retry_join": {{ consul_conf_retry_join | to_json }}, | ||
"enable_syslog": {{ consul_conf_enable_syslog | to_json}}, | ||
"enable_syslog": {{ consul_conf_enable_syslog | to_json }}, | ||
|
||
"leave_on_terminate": {{ consul_conf_leave_on_terminate | to_json}}, | ||
"skip_leave_on_interrupt": {{ consul_conf_skip_leave_on_interrupt | to_json}}, | ||
"rejoin_after_leave": {{ consul_conf_rejoin_after_leave | to_json}} | ||
"leave_on_terminate": {{ consul_conf_leave_on_terminate | to_json }}, | ||
"skip_leave_on_interrupt": {{ consul_conf_skip_leave_on_interrupt | to_json }}, | ||
"rejoin_after_leave": {{ consul_conf_rejoin_after_leave | to_json }} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters