Skip to content

Commit

Permalink
Run tests inside of docker container (#5)
Browse files Browse the repository at this point in the history
Fix issue #4
  • Loading branch information
lukas-bednar authored and KKoukiou committed Mar 2, 2017
1 parent e87fda8 commit 5926fee
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.retry
tests/roles/provision_docker
22 changes: 14 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
---
sudo: required
language: python
python: "2.7"

sudo: true
services:
- docker

# Install ansible
env:
global:
- ANSIBLE_HOST_KEY_CHECKING="False"

# Install python-pip
addons:
apt:
packages:
- python-pip
- python-pip

install:
# Install ansible
- pip install ansible
- pip install ansible docker-py

# Check ansible version
- ansible --version

# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
# Install ansible role tests requirements
- ansible-galaxy install -r tests/requirements.yml -p tests/roles/

script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --skip-tag=poweroff --syntax-check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
# Execute playbook
- ansible-playbook tests/test.yml -i tests/inventory --skip-tag=poweroff
- ansible-playbook tests/test.yml -i tests/inventory

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ None
Role Variables
--------------

None
* **seal\_run\_containerized**

This option allows `seal` role run inside of container, default=false.

Problem is with `/etc/hostname` file which can not be renamed because it
is being bind-mounted.

Dependencies
------------
Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# This option allows run seal role under container
seal_run_containerized: false
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ galaxy_info:
description: Role to seal RHEL machine
company: RedHat
license: GPLv3
min_ansible_version: 1.2
min_ansible_version: 2.2
platforms:
- name: EL
versions:
Expand Down
42 changes: 27 additions & 15 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
---
- name: Load a variable file based on the OS type.
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_os_family }}{{ ansible_distribution_major_version }}.yml"
- "{{ ansible_os_family }}.yml"
- "defaults.yml"

- name: Flag the system for reconfiguration
file:
path: './unconfigured'
Expand All @@ -11,21 +18,26 @@
with_fileglob:
- /etc/ssh/ssh_host_*

- name: reset hostname in RHEL 6
- name: reset hostname on RHEL/CentOS <= 6
lineinfile:
dest: /etc/sysconfig/network
dest: "{{ seal_hostname_file_path }}"
regexp: '^HOSTNAME='
line: 'HOSTNAME=localhost.localdomain'
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 6
unsafe_writes: "{{ seal_run_containerized }}"
when:
- ansible_os_family == "RedHat"
- ansible_distribution_major_version|int <= 6
tags:
- reset_hostname

- name: reset hostname in RHEL 7
lineinfile:
dest: /etc/hostname
regexp: '^HOSTNAME='
line: 'HOSTNAME=localhost.localdomain'
when: ansible_os_family == "RedHat" and ansible_lsb.major_release|int == 7
- name: reset hostname
copy:
dest: "{{ seal_hostname_file_path }}"
content: 'localhost.localdomain'
unsafe_writes: "{{ seal_run_containerized }}"
when:
- ansible_os_family == "RedHat"
- ansible_distribution_major_version|int > 6
tags:
- reset_hostname

Expand All @@ -36,21 +48,21 @@
with_fileglob:
- /etc/udev/rules.d/70-*

- name: remove HWADDR from ifcfg-eth*
- name: remove HWADDR from ifcfg-*
lineinfile:
path: "{{ item }}"
dest: "{{ item }}" # 'path' is new in 2.3
state: absent
regexp: "^HWADDR=.*"
with_fileglob:
- /etc/sysconfig/network-scripts/ifcfg-eth*
- /etc/sysconfig/network-scripts/ifcfg-*

- name: remove UUID from ifcfg-eth*
- name: remove UUID from ifcfg-*
lineinfile:
path: "{{ item }}"
dest: "{{ item }}" # 'path' is new in 2.3
state: absent
regexp: "^UUID=.*"
with_fileglob:
- /etc/sysconfig/network-scripts/ifcfg-eth*
- /etc/sysconfig/network-scripts/ifcfg-*

- name: remove log files and dir from /var/log
file:
Expand Down
2 changes: 1 addition & 1 deletion tests/inventory
Original file line number Diff line number Diff line change
@@ -1 +1 @@
localhost ansible_connection=local
localhost ansible_connection=local ansible_python_interpreter="/usr/bin/env python"
3 changes: 3 additions & 0 deletions tests/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- src: chrismeyersfsu.provision_docker
name: provision_docker
1 change: 1 addition & 0 deletions tests/roles/seal
33 changes: 28 additions & 5 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
---
- hosts: localhost
become: true
become_method: sudo
become_user: root
- name: Bring up docker containers
hosts: localhost
gather_facts: false
vars:
inventory:
- name: seal_centos6
image: "chrismeyers/centos6"
- name: seal_centos7
image: "chrismeyers/centos7"
- name: seal_rhel6
image: "registry.access.redhat.com/rhel6:latest"
- name: seal_rhel7
image: "registry.access.redhat.com/rhel:latest"
# Role doesn't support ubuntu
# - name: seal_ubuntu12
# image: "chrismeyers/ubuntu12.04"
# - name: seal_ubuntu14
# image: "ubuntu-upstart:14.04"
roles:
- ansible-role-seal
- role: provision_docker
provision_docker_inventory: "{{ inventory }}"


- name: Run seal tests on containerized environments
hosts: docker_containers
vars:
seal_run_containerized: yes
roles:
- role: seal
2 changes: 2 additions & 0 deletions vars/RedHat6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
seal_hostname_file_path: /etc/sysconfig/network
2 changes: 2 additions & 0 deletions vars/defaults.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
seal_hostname_file_path: /etc/hostname

0 comments on commit 5926fee

Please sign in to comment.