Skip to content

Commit cffee5f

Browse files
author
Nikita Dugar
authored
Merge pull request #11 from clouddrove/CD-265
upgrade role for centos, amazonlinux & add molecule, pipeline
2 parents 47e7339 + 078d87f commit cffee5f

25 files changed

+509
-48
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/molecule.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
name: Ansible molecule
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
types: [labeled]
8+
jobs:
9+
10+
test:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
node:
16+
- ubuntu
17+
- centos
18+
- amazonlinux
19+
20+
steps:
21+
- name: Check out the codebase.
22+
uses: actions/checkout@v2
23+
24+
- name: Set up Python 3.7.
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: '3.x'
28+
29+
- name: Install test dependencies.
30+
if: ${{ github.event.label.name == 'molecule' }}
31+
run: |
32+
sudo apt-get update
33+
sudo apt-get install ansible -y
34+
pip3 install ansible molecule[docker] docker
35+
36+
- name: 'Run molecule on the ${{ matrix.node }}'
37+
if: ${{ github.event.label.name == 'molecule' }}
38+
run: |
39+
molecule test --scenario-name=${{ matrix.node }} > file.txt
40+
echo 'output<<EOF' >> $GITHUB_ENV
41+
cat file.txt >> $GITHUB_ENV
42+
echo 'EOF' >> $GITHUB_ENV
43+
id: ls
44+
45+
- name: 'PR Comment'
46+
uses: actions-ecosystem/action-create-comment@v1
47+
with:
48+
github_token: ${{ secrets.GITHUB }}
49+
body: |
50+
${{ env.output }}
51+
- name: 'Slack Notification'
52+
uses: clouddrove/action-slack@v2
53+
with:
54+
status: ${{ job.status }}
55+
fields: repo,author
56+
author_name: 'CloudDrove'
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB }}
59+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
60+
if: always()

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
.idea
33
*.iml
44
*.zip
5-
molecule

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
repos:
33

44
- repo: https://github.com/pre-commit/pre-commit-hooks.git
5-
rev: v2.2.3
5+
rev: v3.3.0
66
hooks:
77
- id: end-of-file-fixer
88
- id: trailing-whitespace
@@ -15,7 +15,7 @@ repos:
1515
- id: check-added-large-files
1616

1717
- repo: https://github.com/ansible/ansible-lint.git
18-
rev: v4.1.0
18+
rev: v4.3.7
1919
hooks:
2020
- id: ansible-lint
2121
files: \.(yaml|yml)$

meta/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ galaxy_info:
1818
- trusty
1919
- xenial
2020
- bionic
21+
- name: CentOS
22+
versions:
23+
- 7
24+
- name: Amazonlinux
25+
versions:
26+
- 2
2127
- name: EL
2228
versions:
2329
galaxy_tags:
@@ -27,3 +33,4 @@ galaxy_info:
2733
- ubuntu
2834
- cenos
2935
- linux
36+
- amazonlinux

molecule/amazonlinux/Dockerfile.j2

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Molecule managed
2+
3+
FROM amazonlinux:latest
4+
5+
ENV container docker
6+
7+
RUN yum -y update \
8+
&& yum -y install systemd python python3 bash iproute net-tools sudo \
9+
&& yum clean all
10+
11+
WORKDIR /lib/systemd/system/sysinit.target.wants/
12+
# hadolint ignore=SC2086
13+
RUN for i in *; do [ $i = systemd-tmpfiles-setup.service ] || rm -f "$i"; done
14+
15+
RUN rm -f /lib/systemd/system/multi-user.target.wants/* \
16+
/etc/systemd/system/*.wants/* \
17+
/lib/systemd/system/local-fs.target.wants/* \
18+
/lib/systemd/system/sockets.target.wants/*udev* \
19+
/lib/systemd/system/sockets.target.wants/*initctl* \
20+
/lib/systemd/system/basic.target.wants/* \
21+
/lib/systemd/system/anaconda.target.wants/*
22+
23+
WORKDIR /
24+
RUN systemctl set-default multi-user.target
25+
ENV init /lib/systemd/systemd
26+
VOLUME [ "/sys/fs/cgroup" ]
27+
28+
ENTRYPOINT ["/lib/systemd/systemd"]

molecule/amazonlinux/INSTALL.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
*******
2+
Docker driver installation guide
3+
*******
4+
5+
Requirements
6+
============
7+
8+
* Docker Engine
9+
10+
Install
11+
=======
12+
13+
Please refer to the `Virtual environment`_ documentation for installation best
14+
practices. If not using a virtual environment, please consider passing the
15+
widely recommended `'--user' flag`_ when invoking ``pip``.
16+
17+
.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
18+
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site
19+
20+
.. code-block:: bash
21+
22+
$ pip install 'molecule[docker]'

molecule/amazonlinux/molecule.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
name: docker
6+
platforms:
7+
- name: amazonlinux
8+
image: amazonlinux:latest
9+
dockerfile: ./Dockerfile.j2
10+
privileged: true
11+
command: /sbin/init
12+
volumes:
13+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
14+
- "/var/run/docker.sock:/var/run/docker.sock"
15+
provisioner:
16+
name: ansible
17+
playbooks:
18+
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
19+
scenario:
20+
name: amazonlinux
21+
create_sequence:
22+
- dependency
23+
- create
24+
- prepare
25+
check_sequence:
26+
- dependency
27+
- cleanup
28+
- destroy
29+
- create
30+
- prepare
31+
- converge
32+
- check
33+
- destroy
34+
converge_sequence:
35+
- dependency
36+
- create
37+
- prepare
38+
- converge
39+
destroy_sequence:
40+
- dependency
41+
- cleanup
42+
- destroy
43+
test_sequence:
44+
- dependency
45+
- lint
46+
- cleanup
47+
- destroy
48+
- syntax
49+
- create
50+
- prepare
51+
- converge
52+
- side_effect
53+
- verify
54+
- cleanup
55+
- destroy

molecule/amazonlinux/playbook.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
vars:
5+
example_test_var: "Nothing_to_see_here"
6+
7+
roles:
8+
- role: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
3+
import testinfra.utils.ansible_runner
4+
5+
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
6+
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
7+
8+
9+
def test_hosts_file(host):
10+
f = host.file('/etc/hosts')
11+
12+
assert f.exists
13+
assert f.user == 'root'
14+
assert f.group == 'root'

0 commit comments

Comments
 (0)