Skip to content

Commit

Permalink
add centos support
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavomcarmo committed Nov 1, 2019
1 parent 375d6a5 commit 2ba7b5d
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 19 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ Ansible role to install [Jenkins](https://jenkins.io).
## Dependencies
The role is dependent of [Codeyourinfra's Java 8 Ansible role](https://github.com/codeyourinfra/java8/tree/v1.0), once we need Java to run Jenkins. Java is so installed before the Jenkins installation.
The role is dependent of [Codeyourinfra's Java 8 Ansible role](https://github.com/codeyourinfra/java8), once we need Java to run Jenkins. Java is so installed before the Jenkins installation.
## Build process
The build process is performed by [Travis CI](https://travis-ci.org/codeyourinfra/jenkins). During the build, [Molecule](https://molecule.readthedocs.io) is used to test the role.
## Test yourself
Inside your [Python virtual environment](https://docs.python.org/3/tutorial/venv.html), run:
First of all, create your [Python virtual environment](https://docs.python.org/3/tutorial/venv.html) and activate it:
`pip install -r requirements.txt`
`python -m venv env && source env/bin/activate`

And then:
After that, install all requirements:

`pip install wheel && pip install -r requirements.txt`

Finally, execute the test:

`molecule test`

Expand Down
4 changes: 4 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ galaxy_info:
versions:
- bionic
- xenial
- name: CentOS
versions:
- 7
- 8

galaxy_tags:
- jenkins
Expand Down
4 changes: 2 additions & 2 deletions molecule/default/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ FROM {{ item.registry.url }}/{{ item.image }}
FROM {{ item.image }}
{% endif %}

RUN if [ $(command -v apt-get) ]; then apt-get update && 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; \
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates python-apt aptitude && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python2 sudo python2-devel && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && 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 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; \
Expand Down
12 changes: 12 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@ lint:
platforms:
- name: xenial
image: ubuntu:xenial
groups:
- ubuntu
- name: bionic
image: ubuntu:bionic
groups:
- ubuntu
- name: centos7
image: centos:7
groups:
- centos
- name: centos8
image: centos:8
groups:
- centos
provisioner:
name: ansible
lint:
Expand Down
19 changes: 19 additions & 0 deletions molecule/default/tests/test_centos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import re
import testinfra.utils.ansible_runner

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


def test_java8_is_installed(host):
java8 = host.package("java-1.8.0-openjdk")
assert java8.is_installed
assert java8.version.startswith("1.8.0")


def test_jenkins_is_installed(host):
cmd = host.run("java -jar /usr/lib/jenkins/jenkins.war --version")
assert cmd.rc == 0
pattern = re.compile("^[\\d.]+$")
assert pattern.match(cmd.stdout)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import testinfra.utils.ansible_runner

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


def test_java8_is_installed(host):
Expand Down
14 changes: 14 additions & 0 deletions tasks/centos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Add Jenkins yum repository
yum_repository:
name: jenkins
description: Jenkins-stable
baseurl: http://pkg.jenkins.io/redhat-stable
enabled: yes
gpgcheck: yes
gpgkey: https://jenkins-ci.org/redhat/jenkins-ci.org.key

- name: Install Jenkins
yum:
name: jenkins
update_cache: yes
14 changes: 2 additions & 12 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
---
- name: Install required packages
apt:
name: apt-transport-https
- name: Add the Jenkins apt key
apt_key:
url: https://pkg.jenkins.io/debian-stable/jenkins.io.key
- name: Add the Jenkins repository into sources list
apt_repository:
repo: deb https://pkg.jenkins.io/debian-stable binary/
- name: Install latest Jenkins
apt:
name: jenkins
- name: Execute the appropriate tasks, depending on the distribution.
include: "{{ ansible_distribution | lower }}.yml"
13 changes: 13 additions & 0 deletions tasks/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Install required packages
apt:
name: apt-transport-https
- name: Add the Jenkins apt key
apt_key:
url: https://pkg.jenkins.io/debian-stable/jenkins.io.key
- name: Add the Jenkins repository into sources list
apt_repository:
repo: deb https://pkg.jenkins.io/debian-stable binary/
- name: Install latest Jenkins
apt:
name: jenkins

0 comments on commit 2ba7b5d

Please sign in to comment.