Skip to content

Commit d4d2414

Browse files
committed
Update linting, use centos stream, update actions
1 parent cbd0678 commit d4d2414

10 files changed

+259
-638
lines changed

.github/FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
# if you contributed to this git repo, please feel free to add yourself!
23

34
github: [do1jlr]

.github/marketplace.svg

+72-541
Loading

.github/workflows/hadolint.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
name: hadolint Dockerfile
3+
4+
# yamllint disable-line rule:truthy
5+
on: [push, pull_request]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: checkout repo
12+
uses: actions/checkout@v2
13+
- name: Run Hadolint Action
14+
uses: hadolint/[email protected]
15+
with:
16+
dockerfile: Dockerfile

.github/workflows/shellcheck.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: shellchecking ansible-docker.sh
3+
4+
# yamllint disable-line rule:truthy
5+
on: [push, pull_request]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: checkout repo
12+
uses: actions/checkout@v2
13+
- name: Run ShellCheck
14+
uses: ludeeus/action-shellcheck@master

.github/workflows/yamllint.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
name: 'Yamllint GitHub Actions'
3+
4+
# yamllint disable-line rule:truthy
5+
on:
6+
push:
7+
branches: '*'
8+
pull_request:
9+
branches: '*'
10+
11+
jobs:
12+
yamllint:
13+
name: 'Yamllint'
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: 'Checkout'
17+
uses: actions/checkout@master
18+
- name: 'Yamllint'
19+
uses: karancode/yamllint-github-action@master
20+
with:
21+
yamllint_file_or_dir: '.'
22+
yamllint_config_filepath: './.yamllint'

.yamllint

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
extends: default
3+
4+
rules:
5+
# 100 chars should be enough, but don't fail if a line is longer
6+
line-length:
7+
max: 100
8+
level: warning

Dockerfile

+13-19
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1-
FROM debian:stable
1+
FROM quay.io/centos/centos:stream8
22

33
LABEL "maintainer"="L3D <[email protected]>"
4-
LABEL "repository"="https://github.com/roles-ansible/check-ansible-debian-stable-action.git"
5-
LABEL "homepage"="https://github.com/roles-ansible/check-ansible-debian-stable-action"
4+
LABEL "repository"="https://github.com/roles-ansible/check-ansible-centos-centos8-action.git"
5+
LABEL "homepage"="https://github.com/roles-ansible/check-ansible-centos-centos8-action"
66

7-
LABEL "com.github.actions.name"="check-ansible-debian-stable"
8-
LABEL "com.github.actions.description"="Check ansible role or playbook with Debian stable"
7+
LABEL "com.github.actions.name"="check-ansible-centos-centos8"
8+
LABEL "com.github.actions.description"="Check ansible role or playbook with CentOS centos8"
99
LABEL "com.github.actions.icon"="aperture"
1010
LABEL "com.github.actions.color"="green"
1111

12-
RUN apt-get update -y && apt-get install -y \
13-
software-properties-common \
14-
build-essential \
15-
libffi-dev \
16-
libssl-dev \
17-
python3-dev \
18-
python3-pip \
19-
git \
20-
systemd
12+
# hadolint ignore=DL3041
13+
RUN dnf update --assumeyes \
14+
&& dnf install -y epel-release \
15+
&& dnf install --assumeyes \
16+
ansible git \
17+
&& dnf clean all \
18+
&& ansible --version
2119

22-
RUN pip3 install setuptools && pip3 install ansible
23-
24-
RUN ansible --version
25-
26-
ADD ansible-docker.sh /ansible-docker.sh
20+
COPY ansible-docker.sh /ansible-docker.sh
2721
ENTRYPOINT ["/ansible-docker.sh"]

README.md

+64-49
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,79 @@
1-
[![Github Marketplace](https://raw.githubusercontent.com/roles-ansible/check-ansible-debian-stable-action/master/.github/marketplace.svg?sanitize=true)](https://github.com/marketplace/actions/check-ansible-debian-stable)
2-
[![MIT License](https://raw.githubusercontent.com/roles-ansible/check-ansible-debian-stable-action/master/.github/license.svg?sanitize=true)](https://github.com/roles-ansible/check-ansible-debian-stable-action/blob/master/LICENSE)
1+
[![Github Marketplace](https://raw.githubusercontent.com/roles-ansible/check-ansible-centos-centos8-action/master/.github/marketplace.svg?sanitize=true)](https://github.com/marketplace/actions/check-ansible-centos-centos8)
2+
[![MIT License](https://raw.githubusercontent.com/roles-ansible/check-ansible-centos-centos8-action/master/.github/license.svg?sanitize=true)](https://github.com/roles-ansible/check-ansible-centos-centos8-action/blob/master/LICENSE)
33

4-
Check Ansible Debian stable
4+
Check Ansible CentOS centos8
55
=======================
6-
This action allows you to test your ansible role or your playbook in a Docker Container with ``debian:stable``.
6+
This action allows you to test your ansible role or your playbook in a Docker Container with ``centos:centos8``.
77

88
## Usage
9-
To use the action simply create an ``ansible-debian-stable.yml`` *(or choose custom ``*.yml`` name)* in the ``.github/workflows/`` directory.
9+
To use the action simply create an ``ansible-centos-centos8.yml`` *(or choose custom ``*.yml`` name)* in the ``.github/workflows/`` directory.
1010

1111
For example:
1212

1313
```yaml
14-
name: Ansible check debian:stable # feel free to pick your own name
14+
---
15+
name: Ansible check centos:stream8 # feel free to pick your own name
1516

17+
# yamllint disable-line rule:truthy
1618
on: [push, pull_request]
1719

1820
jobs:
1921
build:
20-
2122
runs-on: ubuntu-latest
2223

2324
steps:
24-
# Important: This sets up your GITHUB_WORKSPACE environment variable
25-
- uses: actions/checkout@v2
26-
27-
- name: ansible check with debian:stable
28-
# replace "master" with any valid ref
29-
uses: roles-ansible/check-ansible-debian-stable-action@master
30-
with:
31-
targets: "./"
32-
# [required]
33-
# Paths to your ansible role or playboox.yml you want to test
34-
# Some Examples:
35-
# targets: "role/my_role/"
36-
# targets: "site.yml"
37-
#
38-
# group: ""
39-
# [optional]
40-
# When testing playbooks you have to tell ansible
41-
# the group you that we write in our hosts file.
42-
# example:
43-
# group: 'servers'
44-
# hosts: ""
45-
# [optional]
46-
# When testing playbooks you have to give one example
47-
# host this action should use to test your playbook.
48-
# > We only spawn one docker container that mean
49-
# > we can only test one host at the time. Sorry
50-
# some examples:
51-
# hosts: 'localhost'
52-
# hosts: 'srv01.example.com'
53-
# requirements
54-
# [optional]
55-
# When testing playbooks and you are using ansible galaxy,
56-
# you may be interested in installing your requirements
57-
# from ansible galaxy.
58-
# To do this please provide us either the role name directly
59-
# requirements: 'do1jlr.ansible_version'
60-
# or your requiements.yml file.
61-
# requirements: 'requirements.yml'
25+
# Important: This sets up your GITHUB_WORKSPACE environment variable
26+
- name: checkout git repo
27+
uses: actions/checkout@v3
28+
29+
- name: ansible check with quay.io/centos/centos:stream8
30+
# optionally replace "master" with any valid git ref
31+
uses: roles-ansible/check-ansible-centos-centos8-action@master
32+
with:
33+
targets: "./"
34+
# [required]
35+
# Paths to your ansible role or playboox.yml you want to test
36+
# Some Examples:
37+
# targets: "role/my_role/"
38+
# targets: "site.yml"
39+
#
40+
# group: ""
41+
# [optional]
42+
# When testing playbooks you have to tell ansible
43+
# the group you that we write in our hosts file.
44+
# example:
45+
# group: 'servers'
46+
#
47+
# hosts: ""
48+
# [optional]
49+
# When testing playbooks you have to give one example
50+
# host this action should use to test your playbook.
51+
# > We only spawn one docker container that mean
52+
# > we can only test one host at the time. Sorry
53+
# some examples:
54+
# hosts: 'localhost'
55+
# hosts: 'srv01.example.com'
56+
#
57+
# requirements: ""
58+
# [optional]
59+
# When testing playbooks and you are using ansible galaxy,
60+
# you may be interested in installing your requirements
61+
# from ansible galaxy.
62+
# To do this please provide us either the role name directly
63+
# requirements: 'do1jlr.ansible_version'
64+
# or your requiements.yml file.
65+
# requirements: 'requirements.yml'
66+
#
67+
# tags: ""
68+
# [optional]
69+
# If you want to limit the test to some tags, you can use this
70+
# tags or the skiptags option. It will trigger the --tags $tags
71+
# option to ansible.
72+
#
73+
# skiptags: ""
74+
# [optional]
75+
# See tags. This will trigger the --skip-tags $skiptags option
76+
# to ansible.
6277
```
6378

6479
Alternatively, you can run the ansible check only on certain branches:
@@ -86,7 +101,7 @@ The Dockerfile and associated scripts and documentation in this project are rele
86101
87102
Credits
88103
--------------
89-
The initial GitHub action has been created by [Stefan Stölzle](/stoe) at
90-
[stoe/actions](https://github.com/stoe/actions).<br/>
91-
It was used by ansible for lint checks at [ansible/ansible-lint-action](https://github.com/ansible/ansible-lint-action.git)<br/>
92-
It was modified from [L3D](github.com/do1jlr) to check ansible roles.
104+
+ The initial GitHub action has been created by [Stefan Stölzle](https://github.com/stoe) at
105+
[stoe/actions](https://github.com/stoe/actions).
106+
+ It was used by ansible for lint checks at [ansible/ansible-lint-action](https://github.com/ansible/ansible-lint-action.git)
107+
+ It was modified from [L3D](github.com/do1jlr) to check ansible roles.

action.yml

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
name: Check Ansible Debian stable
2-
description: Check ansible role or playbook with the debian:stable docker container
1+
---
2+
name: Check Ansible CentOS centos8
3+
description: Check ansible role or playbook with the centos:centos8 docker container
34
author: L3D <[email protected]>
45

5-
inputs:
6+
inputs:
67
targets:
78
description: |
89
Paths to the ansible role or playbook you want to be tested.
@@ -33,6 +34,16 @@ inputs:
3334
or your requiements.yml file.
3435
-> e.g. 'requirements.yml'
3536
required: false
37+
tags:
38+
description: |
39+
If you are using tags and you want to pick which tags
40+
you are going to check you can optionally define them here.
41+
required: false
42+
skiptags:
43+
desctiption:
44+
If you are using tags and you want explicit skip some of them,
45+
you can define them here.
46+
required: false
3647
runs:
3748
using: docker
3849
image: Dockerfile
@@ -41,6 +52,8 @@ runs:
4152
HOSTS: ${{ inputs.hosts }}
4253
GROUP: ${{ inputs.group }}
4354
REQUIREMENTS: ${{ inputs.requirements }}
55+
TAGS: ${{ inputs.tags }}
56+
SKIPTAGS: $(( input.skiptags }}
4457
branding:
45-
icon: 'aperture'
58+
icon: 'check-circle'
4659
color: 'green'

ansible-docker.sh

+32-25
Original file line numberDiff line numberDiff line change
@@ -8,70 +8,77 @@ set -x
88
# [required] TARGETS : Path to your ansible role or to a playbook .yml file you want to be tested.
99
# (e.g, './' or 'roles/my_role/' for roles or 'site.yml' for playbooks)
1010

11-
1211
ansible::prepare() {
1312
: "${TARGETS?No targets to check. Nothing to do.}"
1413
: "${GITHUB_WORKSPACE?GITHUB_WORKSPACE has to be set. Did you use the actions/checkout action?}"
15-
pushd ${GITHUB_WORKSPACE}
14+
pushd "${GITHUB_WORKSPACE}"
1615

1716
# generate ansible.cfg
18-
echo -e """
17+
cat <<EOF | tee ansible.cfg
1918
[defaults]
20-
inventory = host.ini
21-
nocows = True
22-
host_key_checking = False
19+
inventory = hosts.ini
20+
nocows = true
21+
host_key_checking = false
2322
forks = 20
2423
fact_caching = jsonfile
2524
fact_caching_connection = $HOME/facts
2625
fact_caching_timeout = 7200
27-
stdout_callback = yaml
2826
ansible_python_interpreter=/usr/bin/python3
2927
ansible_connection=local
30-
""" | tee ansible.cfg
28+
EOF
3129

3230
# create host list
33-
echo -e "[local]\nlocalhost ansible_python_interpreter=/usr/bin/python3 ansible_connection=local" | tee host.ini
31+
cat <<EOF | tee hosts.ini
32+
[local]
33+
localhost ansible_python_interpreter=/usr/bin/python3 ansible_connection=local
34+
EOF
3435
}
36+
3537
ansible::test::role() {
3638
: "${TARGETS?No targets to check. Nothing to do.}"
3739
: "${GITHUB_WORKSPACE?GITHUB_WORKSPACE has to be set. Did you use the actions/checkout action?}"
38-
pushd ${GITHUB_WORKSPACE}
40+
pushd "${GITHUB_WORKSPACE}"
3941

4042
# generate playbook to be executed
41-
echo -e """---
42-
- name: test a ansible role
43-
hosts: localhost
44-
tags: default
45-
roles:
46-
- \""${TARGETS}"\"
47-
""" | tee -a deploy.yml
43+
cat <<EOF | tee -a deploy.yml
44+
---
45+
- name: test a ansible role
46+
hosts: localhost
47+
tags: default
48+
roles:
49+
- "${TARGETS}"
50+
EOF
4851

4952
# execute playbook
50-
ansible-playbook --connection=local --limit localhost deploy.yml
53+
ansible-playbook --connection=local --limit localhost deploy.yml --tags "${TAGS}" --skip-tags "${SKIPTAGS}"
5154
}
5255
ansible::test::playbook() {
5356
: "${TARGETS?No targets to check. Nothing to do.}"
5457
: "${GITHUB_WORKSPACE?GITHUB_WORKSPACE has to be set. Did you use the actions/checkout action?}"
5558
: "${HOSTS?at least one valid host is required to check your playbook!}"
5659
: "${GROUP?Please define the group your playbook is written for!}"
57-
pushd ${GITHUB_WORKSPACE}
60+
pushd "${GITHUB_WORKSPACE}"
5861

59-
echo -e "[${GROUP}]\n${HOSTS} ansible_python_interpreter=/usr/bin/python3 ansible_connection=local ansible_host=127.0.0.1" | tee host.ini
62+
cat <<EOF | tee hosts.ini
63+
[${GROUP}]
64+
${HOSTS} ansible_python_interpreter=/usr/bin/python3 ansible_connection=local ansible_host=127.0.0.1
65+
EOF
6066

6167
# execute playbook
62-
ansible-playbook --connection=local --inventory host.ini ${TARGETS}
68+
# shellcheck disable=SC2086
69+
ansible-playbook --connection=local --inventory host.ini ${TARGETS}
6370
}
6471

6572
# make sure git is up to date
6673
git submodule update --init --recursive
6774
if [[ "${REQUIREMENTS}" == *.yml ]]
6875
then
69-
ansible-galaxy install -r ${REQUIREMENTS}
76+
ansible-galaxy install -r "${REQUIREMENTS}"
7077
else
71-
[ ! -z "${REQUIREMENTS}" ] && ansible-galaxy install ${REQUIREMENTS}
78+
[ -n "${REQUIREMENTS}" ] && ansible-galaxy install "${REQUIREMENTS}"
7279
fi
73-
if [ "$0" = "$BASH_SOURCE" ] ; then
74-
>&2 echo -E "\nRunning Ansible debian check...\n"
80+
if [ "$0" = "${BASH_SOURCE[*]}" ] ; then
81+
>&2 printf "Running Ansible debian check...\n"
7582
ansible::prepare
7683
if [[ "${TARGETS}" == *.yml ]]
7784
then

0 commit comments

Comments
 (0)