-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GITHUB-17] Update to Latest Standards
- Loading branch information
1 parent
be91cc1
commit 0174723
Showing
31 changed files
with
624 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
# http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
[*.{yml,md,json.j2}] | ||
indent_style = space | ||
insert_final_newline = false | ||
trim_trailing_whitespace = true | ||
|
||
[*.cf] | ||
indent_size = 2 | ||
max_line_length = 119 | ||
|
||
[*.md] | ||
indent_size = 2 | ||
trim_trailing_whitespace = false | ||
|
||
[*.py] | ||
max_line_length = 119 | ||
|
||
[*.{js,json,yaml,yml}] | ||
indent_size = 2 | ||
|
||
[Makefile] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
|
||
- 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] | ||
|
||
- repo: git://github.com/pre-commit/pre-commit-hooks | ||
sha: v0.9.1 | ||
hooks: | ||
- id: check-json | ||
- id: flake8 | ||
- id: trailing-whitespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v1.2 | ||
v2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,83 @@ | ||
include .make | ||
|
||
ANSIBLE_INSTALL_VERSION ?= 2.2.3.0 | ||
ANSIBLE_CONFIG ?= tests/ansible.cfg | ||
ROLE_NAME ?= $(shell basename $$(pwd)) | ||
TEST_PLAYBOOK ?= test.yml | ||
VAGRANT_BOX ?= ubuntu/trusty64 | ||
PATH := $(PWD)/.venv_$(ANSIBLE_INSTALL_VERSION)/bin:$(shell printenv PATH) | ||
PATH := $(PWD)/.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin:$(shell printenv PATH) | ||
SHELL := env PATH=$(PATH) /bin/bash | ||
|
||
.DEFAULT_GOAL := help | ||
.PHONY: help | ||
.PHONY: all clean destroy help test | ||
|
||
|
||
_check_venv: | ||
@if [ ! -e .venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/activate ]; then \ | ||
echo -e "\033[0;31mERROR: No virtualenv found - run 'make deps' first\033[0m"; \ | ||
false; \ | ||
fi | ||
|
||
|
||
## Make deps, test | ||
all: deps test | ||
|
||
|
||
## Activate the virtualenv | ||
activate: _check_venv | ||
@echo -e "\033[0;32mINFO: Activating venv_ansible$(ANSIBLE_INSTALL_VERSION) (ctrl-d to exit)\033[0m" | ||
@exec $(SHELL) --init-file .venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/activate | ||
|
||
|
||
## Destroy docker instances, remove virtualenv, molecule temp, .pyc files | ||
clean: destroy | ||
rm -rf .venv_ansible* | ||
rm -rf molecule/*/.cache/ | ||
rm -rf molecule/*/.molecule/ | ||
find . -name "*.pyc" -exec rm {} \; | ||
|
||
export ANSIBLE_CONFIG | ||
export PATH | ||
export VAGRANT_BOX | ||
export TEST_PLAYBOOK | ||
|
||
all: test clean | ||
## Run 'molecule destroy' | ||
destroy: | ||
@if [ -x .venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/molecule ]; then \ | ||
.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/molecule destroy; \ | ||
elif (which -s molecule); then \ | ||
echo -e "\033[0;33mWARNING: molecule not found in virtualenv - trying to use molecule in PATH\033[0m"; \ | ||
molecule destroy; \ | ||
else \ | ||
echo -e "\033[0;33mWARNING: molecule not found - either remove potential containers manually or run 'make deps' first\033[0m"; \ | ||
fi | ||
|
||
## Run tests on any file change | ||
watch: test_deps | ||
while sleep 1; do \ | ||
find defaults/ handlers/ meta/ tasks/ templates/ tests/test.yml \ | ||
| entr -d make lint vagrant; \ | ||
## Login to docker container named '%' | ||
login_%: _check_venv | ||
@echo -e "\033[0;32mINFO: Logging into $(subst login_,,$@) (ctrl-d to exit)\033[0m" | ||
@.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/molecule login --host $(subst login_,,$@) | ||
|
||
## Run 'molecule test --destroy=never' (run 'make destroy' to destroy containers) | ||
test: _check_venv | ||
@.venv_ansible$(ANSIBLE_INSTALL_VERSION)/bin/molecule test --destroy=never | ||
|
||
|
||
## Create virtualenv, install dependencies | ||
deps: | ||
@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: _check_venv | ||
@while sleep 1; do \ | ||
find defaults/ files/ handlers/ meta/ molecule/*/*.yml molecule/*/test/*.py tasks/ templates/ vars/ 2> /dev/null \ | ||
| entr -d make test; \ | ||
done | ||
|
||
## Run tests | ||
test: lint test_deps vagrant | ||
|
||
## Install test dependencies | ||
test_deps: .venv_$(ANSIBLE_INSTALL_VERSION) tests/roles | ||
|
||
tests/roles: | ||
mkdir -p tests/roles | ||
ln -s ../.. tests/roles/sansible.$(ROLE_NAME) | ||
ansible-galaxy install -p tests/roles -r tests/local_requirements.yml --ignore-errors | ||
|
||
## ! Executes Ansible tests using local connection | ||
# run it ONLY from within a test VM. | ||
# If you want to test this role, run `make test` instead. | ||
# Example: make test_ansible | ||
# make test_ansible TEST_PLAYBOOK=test-something-else.yml | ||
test_ansible: test_ansible_build test_ansible_configure | ||
cd tests && ansible-playbook \ | ||
--inventory inventory \ | ||
--connection local \ | ||
--tags assert \ | ||
$(TEST_PLAYBOOK) | ||
|
||
## ! Executes Ansible tests using local connection | ||
# run it ONLY from witinh a test VM. | ||
# Example: make test_ansible_build | ||
# make test_ansible_build TEST_PLAYBOOK=test-something-else.yml | ||
test_ansible_%: | ||
cd tests && ansible-playbook \ | ||
--inventory inventory \ | ||
--connection local \ | ||
--tags=$(subst test_ansible_,,$@) \ | ||
$(TEST_PLAYBOOK) | ||
cd tests && ansible-playbook \ | ||
--inventory inventory \ | ||
--connection local \ | ||
--tags=$(subst test_ansible_,,$@) \ | ||
$(TEST_PLAYBOOK) \ | ||
| grep -q 'changed=0.*failed=0' \ | ||
&& (echo 'Idempotence test: pass' && exit 0) \ | ||
|| (echo 'Idempotence test: fail' && exit 1) | ||
|
||
## Start and (re)provisiom Vagrant test box | ||
vagrant: | ||
cd tests && vagrant up --no-provision | ||
cd tests && vagrant provision | ||
@echo "- - - - - - - - - - - - - - - - - - - - - - -" | ||
@echo " Provisioning Successful" | ||
@echo "- - - - - - - - - - - - - - - - - - - - - - -" | ||
|
||
## Execute simple Vagrant command | ||
# Example: make vagrant_ssh | ||
# make vagrant_halt | ||
vagrant_%: | ||
cd tests && vagrant $(subst vagrant_,,$@) | ||
|
||
## Installs a virtual environment and all python dependencies | ||
.venv_%: | ||
virtualenv .venv_$(ANSIBLE_INSTALL_VERSION) | ||
.venv_$(ANSIBLE_INSTALL_VERSION)/bin/pip install -r requirements.txt --ignore-installed | ||
.venv_$(ANSIBLE_INSTALL_VERSION)/bin/pip install ansible==$(ANSIBLE_INSTALL_VERSION) | ||
virtualenv --relocatable .venv_$(ANSIBLE_INSTALL_VERSION) | ||
|
||
## lint Ansible files | ||
lint: .venv_$(ANSIBLE_INSTALL_VERSION) | ||
find defaults/ handlers/ meta/ tasks/ templates/ -name "*.yml" | xargs -I{} ansible-lint {} | ||
|
||
## Prints this help | ||
|
||
help: | ||
@awk -v skip=1 \ | ||
'/^##/ { sub(/^[#[:blank:]]*/, "", $$0); doc_h=$$0; doc=""; skip=0; next } \ | ||
skip { next } \ | ||
/^#/ { doc=doc "\n" substr($$0, 2); next } \ | ||
/:/ { sub(/:.*/, "", $$0); printf "\033[34m%-30s\033[0m\033[1m%s\033[0m %s\n\n", $$0, doc_h, doc; skip=1 }' \ | ||
/:/ { sub(/:.*/, "", $$0); \ | ||
printf "\033[34m%-30s\033[0m\033[1m%s\033[0m %s\n\n", $$0, doc_h, doc; skip=1 }' \ | ||
$(MAKEFILE_LIST) | ||
|
||
## Removes all downloaded dependencies | ||
clean: | ||
rm -rf .venv_* | ||
rm -rf tests/roles | ||
cd tests && (vagrant destroy || echo "skipping vagrant destroy") | ||
|
||
.make: | ||
touch .make |
Oops, something went wrong.