Skip to content

Commit

Permalink
ansible-lint Test
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisconrad committed Jun 14, 2021
1 parent bcb4cbc commit 9e675bd
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 99 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ max_line_length = 119

[*.{js,json,yaml,yml}]
indent_size = 2
insert_final_newline = true

[Makefile]
indent_style = tab
47 changes: 24 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
---

- repo: https://github.com/willthames/ansible-lint.git
sha: v3.4.17
hooks:
- id: ansible-lint
types: [yaml]
exclude: >
(?x)^(
\.travis\.yml|
molecule/.*/\.molecule/.*|
molecule/.*/create\.yml
)$
- id: ansible-lint
files: \.travis\.yml
args: [-x, ANSIBLE0008]
- id: ansible-lint
files: molecule/.*/create\.yml
args: [-x, ANSIBLE0016]
repos:
- repo: https://github.com/willthames/ansible-lint.git
rev: v4.2.0
hooks:
- id: ansible-lint
types: [yaml]
exclude: >
(?x)^(
\.travis\.yml|
molecule/.*/\.molecule/.*|
molecule/.*/create\.yml
)$
- id: ansible-lint
files: \.travis\.yml
args: [-x, ANSIBLE0008]
- id: ansible-lint
files: molecule/.*/create\.yml
args: [-x, ANSIBLE0016]

- repo: git://github.com/pre-commit/pre-commit-hooks
sha: v0.9.1
hooks:
- id: check-json
- id: flake8
- id: trailing-whitespace
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
hooks:
- id: check-json
- id: flake8
- id: trailing-whitespace
17 changes: 7 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
---

group: stable
dist: xenial
sudo: required
dist: bionic

os:
- linux

language: python
python:
- 2.7
- 3.6
cache: pip

branches:
Expand All @@ -15,17 +17,12 @@ branches:
- master

env:
- ANSIBLE_INSTALL_VERSION=2.5.15
- ANSIBLE_INSTALL_VERSION=2.6.16
- ANSIBLE_INSTALL_VERSION=2.7.10
- ANSIBLE_INSTALL_VERSION=2.8.18
- ANSIBLE_INSTALL_VERSION=2.9.16

services:
- docker

before_install:
- sudo apt-get update -qq
- sudo apt-get install -o Dpkg::Options::="--force-confold" --force-yes -y docker-ce

install:
- make deps

Expand Down
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.5
v2.6
35 changes: 35 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# Based on ansible-lint config
extends: default
ignore: .venv_ansible*

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: enable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: enable
key-duplicates: enable
line-length:
max: 159
new-line-at-end-of-file: enable
new-lines:
type: unix
trailing-spaces: enable
truthy: disable
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2018
Copyright (c) 2021

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 9 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ANSIBLE_INSTALL_VERSION ?= 2.7.10
ANSIBLE_INSTALL_VERSION ?= 2.9.16
SCENARIO ?= all
PATH := $(PWD)/.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin:$(shell printenv PATH)
SHELL := env PATH=$(PATH) /bin/bash

Expand Down Expand Up @@ -54,26 +55,23 @@ login_%: .venv_ansible$(ANSIBLE_INSTALL_VERSION)

## Run 'molecule test --destroy=never' (run 'make destroy' to destroy containers)
test: .venv_ansible$(ANSIBLE_INSTALL_VERSION)
@.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/molecule test $(SCENARIO_OPT) --destroy=never

@if [ "$(SCENARIO_OPT)" == "--all" ]; then \
echo "Testing all scenarios"; \
.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/molecule test $(SCENARIO_OPT); \
else \
echo "Testing only the $(SCENARIO) scenario"; \
.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/molecule test $(SCENARIO_OPT) --destroy=never; \
fi

# shortcut for creating venv
.venv: .venv_ansible$(ANSIBLE_INSTALL_VERSION)


## Create virtualenv, install dependencies
.venv_ansible$(ANSIBLE_INSTALL_VERSION):
@if (python -V 2>&1 | grep -qv "Python 2.7"); then \
echo -e "\033[0;31mERROR: Only Python 2.7 is supported at this stage\033[0m"; \
false; \
fi
virtualenv .venv_ansible$(ANSIBLE_INSTALL_VERSION)
.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/pip install -r requirements.txt --ignore-installed
.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/pip install ansible==$(ANSIBLE_INSTALL_VERSION)
virtualenv --relocatable .venv_ansible$(ANSIBLE_INSTALL_VERSION)
@echo -e "\033[0;32mINFO: Run 'make activate' to activate the virtualenv for this shell\033[0m"


## Run 'make test' on any file change
watch: .venv_ansible$(ANSIBLE_INSTALL_VERSION)
@while sleep 1; do \
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ This role uses one tag: **build**

See [defaults/main.yml](defaults/main.yml)

~

## Testing

### Test all scenarios

`make test`
Note: The test container/s will NOT be left running, so for troubleshooting you may want to specify the scenario as per option below

### Test a single, specified scenario

`SCENARIO=<your_scenario> make test`
Note: The test container/s WILL be left running. They can be removed with `make destroy` or `make clean`.

## Examples

Expand Down
6 changes: 3 additions & 3 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ galaxy_info:
author: Sansible
description: PHP and FPM installation
license: MIT
min_ansible_version: 2.5
min_ansible_container_version: 2.5
min_ansible_version: 2.8
min_ansible_container_version: 2.8
platforms:
- name: Ubuntu
versions:
- xenial
- bionic
- focal
galaxy_tags:
- development
- fpm
Expand Down
30 changes: 9 additions & 21 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ driver:
name: docker

platforms:
- name: sansible_php-xenial
image: solita/ubuntu-systemd:xenial
- name: sansible-php-focal
image: jrei/systemd-ubuntu:20.04
command: /sbin/init
capabilities:
- SYS_ADMIN
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: sansible_php-bionic
image: solita/ubuntu-systemd:bionic
- name: sansible-php-bionic
image: jrei/systemd-ubuntu:18.04
command: /sbin/init
capabilities:
- SYS_ADMIN
Expand All @@ -21,22 +21,12 @@ platforms:

provisioner:
name: ansible
config_options:
defaults:
hash_behaviour: merge
lint:
name: ansible-lint

lint:
name: yamllint
options:
config-data:
extends: default
ignore: .venv_ansible*
rules:
line-length:
max: 159
truthy: disable
lint: |
set -e
yamllint .
ansible-lint
flake8 molecule/
dependency:
name: galaxy
Expand All @@ -48,5 +38,3 @@ scenario:

verifier:
name: testinfra
lint:
name: flake8
12 changes: 12 additions & 0 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
apt:
name:
- apt-transport-https
- gpg
- lsb-release
- net-tools
- python3-setuptools
- unzip
update_cache: yes

- name: Symlink pip3 for TestInfra
become: yes
file:
dest: /usr/bin/pip
force: yes
mode: 0751
src: /usr/bin/pip3
state: link
27 changes: 9 additions & 18 deletions molecule/php7/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ driver:
name: docker

platforms:
- name: sansible_php-7-xenial
image: solita/ubuntu-systemd:xenial
- name: sansible-php-7-focal
image: jrei/systemd-ubuntu:20.04
command: /sbin/init
capabilities:
- SYS_ADMIN
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: sansible_php-7-bionic
image: solita/ubuntu-systemd:bionic
- name: sansible-php-7-bionic
image: jrei/systemd-ubuntu:18.04
command: /sbin/init
capabilities:
- SYS_ADMIN
Expand All @@ -21,19 +21,12 @@ platforms:

provisioner:
name: ansible
lint:
name: ansible-lint

lint:
name: yamllint
options:
config-data:
extends: default
ignore: .venv_ansible*
rules:
line-length:
max: 159
truthy: disable
lint: |
set -e
yamllint .
ansible-lint
flake8 molecule/
dependency:
name: galaxy
Expand All @@ -45,5 +38,3 @@ scenario:

verifier:
name: testinfra
lint:
name: flake8
12 changes: 12 additions & 0 deletions molecule/php7/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
apt:
name:
- apt-transport-https
- gpg
- lsb-release
- net-tools
- python3-setuptools
- unzip
update_cache: yes

- name: Symlink pip3 for TestInfra
become: yes
file:
dest: /usr/bin/pip
force: yes
mode: 0751
src: /usr/bin/pip3
state: link
11 changes: 7 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
docker==3.5.1
flake8==3.7.6
molecule==2.19.0
yamllint==1.15.0
ansible==2.9.16
ansible-lint==4.3.7
docker==4.2.2
flake8==3.8.3
molecule==3.0.6
testinfra==5.2.2
yamllint==1.24.2
6 changes: 1 addition & 5 deletions tasks/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
dest: /usr/local/src/php.asc
mode: 0644
url: "{{ sansible_php_repo_keyserver }}/pks/lookup?op=get&search=0x{{ sansible_php_repo_key_id }}"
retries: 2
delay: 10
register: sansible_php_pgp_result
until: sansible_php_pgp_result is succeeded

- name: Ensures PHP PGP key is known
become: yes
Expand All @@ -33,7 +29,7 @@
- "{{ sansible_php_version }}-common"
- "{{ sansible_php_version }}-fpm"
- "{{ sansible_php_version }}-cli"
when: sansible_php_install_base_packages == true
when: sansible_php_install_base_packages

- name: Install base PHP modules
become: yes
Expand Down
Loading

0 comments on commit 9e675bd

Please sign in to comment.