Skip to content
Permalink
Browse files

Merge branch 'molecule'

  • Loading branch information...
Frzk committed Mar 22, 2019
2 parents 05907ef + 4d78528 commit a7dd46897834c87e5af8dcd5a2522ca1a510a076
@@ -1,56 +1,29 @@
---
sudo: required
language: bash
language: python
services:
- docker

# Build matrix
env:
- distribution: centos
version: 7
- distribution: debian
version: 9
- distribution: ubuntu
version: 16.04
- distribution: ubuntu
version: 18.04

before_install:
# Pull the image corresponding to the environment vars from Docker Hub:
- docker pull "kblr/${distribution}${version}-ansible:latest"
global:
- ROLENAME=chrony
matrix:
- MOLECULE_DISTRIB=centos7
- MOLECULE_DISTRIB=debian9
- MOLECULE_DISTRIB=ubuntu16.04
- MOLECULE_DISTRIB=ubuntu18.04
- MOLECULE_DISTRIB=archlinux

install:
- pip install molecule docker

before_script:
- cd ..
- mv ansible-role-$ROLENAME frzk.$ROLENAME
- cd frzk.$ROLENAME

script:
# 0/ Run the container:
- >
docker run
--name "${TRAVIS_COMMIT}.${distribution}-${version}"
--detach
--privileged
--mount type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly
--mount type=bind,source="$(pwd)",target=/etc/ansible/roles/under_test,readonly
"kblr/${distribution}${version}-ansible:latest"
# 1/ Check role syntax:
- >
docker exec "${TRAVIS_COMMIT}.${distribution}-${version}"
ansible-playbook -v /etc/ansible/roles/under_test/tests/test.yml --syntax-check
# 2/ Check first run:
- >
docker exec "${TRAVIS_COMMIT}.${distribution}-${version}"
ansible-playbook -v /etc/ansible/roles/under_test/tests/test.yml
# 3/ Check idempotence:
- >
docker exec "${TRAVIS_COMMIT}.${distribution}-${version}"
ansible-playbook -v /etc/ansible/roles/under_test/tests/test.yml
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
after_script:
# Remove container:
- docker rm -f "${TRAVIS_COMMIT}.${distribution}-${version}"
- molecule --debug test

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
@@ -1,6 +1,6 @@
---
chrony_service_name: chronyd
chrony_timezone: "Etc/UTC"
chrony_timezone: "Etc/UTC"
chrony_ntp_pools:
- pool.ntp.org iburst maxpoll 10
chrony_ntp_servers: []
@@ -24,4 +24,6 @@ galaxy_info:
- system
- ntp
- chrony
- date
- time
...
@@ -0,0 +1,30 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
options:
config-file: molecule/default/yamllint.yml
platforms:
- name: instance
image: "kblr/${MOLECULE_DISTRIB:-centos7}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
provisioner:
name: ansible
lint:
name: ansible-lint
playbooks:
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
...
@@ -0,0 +1,5 @@
---
- name: Converge
hosts: all
roles:
- role: frzk.chrony
@@ -0,0 +1,32 @@
#!/usr/bin/env python
# coding: utf8

import os
from testinfra.utils.ansible_runner import AnsibleRunner


testinfra_hosts = AnsibleRunner(os.environ["MOLECULE_INVENTORY_FILE"])\
.get_hosts("all")


def test_chrony_is_installed(host):
"""
"""
package_name = "chrony"

chrony = host.package(package_name)
assert chrony.is_installed


def test_chrony_running_and_enabled(host):
"""
"""
os = host.system_info.distribution
service_name = "chronyd"

if os in ("debian", "ubuntu"):
service_name = "chrony"

chrony = host.service(service_name)
assert chrony.is_running
assert chrony.is_enabled
@@ -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'
@@ -0,0 +1,7 @@
---
extends: default
rules:
line-length:
max: 120
level: warning
...
@@ -8,7 +8,7 @@
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
skip: yes
skip: true

- name: Set up timezone
timezone:
@@ -36,13 +36,15 @@
notify: Restart chrony

- name: Install
include_tasks: "setup-{{ ansible_os_family }}.yml"
package:
name: "chrony"
state: present

- name: Disable conflicting services
service:
name: "{{ item }}"
state: stopped
enabled: no
enabled: false
register: disable_service_result
failed_when: (disable_service_result is failed)
and ('Could not find the requested service' not in disable_service_result.msg)
@@ -58,5 +60,5 @@
- name: Enable service
service:
name: "{{ chrony_service_name }}"
enabled: yes
enabled: true
...

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

0 comments on commit a7dd468

Please sign in to comment.
You can’t perform that action at this time.