Skip to content

Commit

Permalink
add Ansible check in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Vallar <[email protected]>
  • Loading branch information
Val committed Feb 3, 2019
1 parent a135efa commit 9ba41e4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
10 changes: 9 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
<%
ANSIBLE_CHECK_MODE = \
ENV['ANSIBLE_CHECK_MODE']&.match? /^(1|[Yy](es)?|[Tt](rue)?)$/
SYSTEMCTL_REPLACEMENT_URL = \
"https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement\
/master/files/docker/systemctl.py"
Expand Down Expand Up @@ -78,13 +81,15 @@ driver:
- DEBIAN_FRONTEND=noninteractive apt-get install -y python python-apt
<% end %>



provisioner:
name: ansible_push
playbook: site.yml
sudo: true
sudo_user: root
ask_vault_pass: false
idempotency_test: true
idempotency_test: <%= ! ANSIBLE_CHECK_MODE %>
fail_non_idempotent: true
chef_bootstrap_url: nil

Expand All @@ -108,6 +113,7 @@ suites:
custom_instance_name: default-sandbox.local
extra_vars:
ansible_fqdn: default-sandbox.local
ansible_check_mode: <%= ANSIBLE_CHECK_MODE %>
verifier:
inspec_tests:
- spec/roles/common/sshd_spec.rb
Expand All @@ -124,6 +130,8 @@ transport:
request_pty: false
timeout: 3
non_interactive: true
<% unless ANSIBLE_CHECK_MODE %>

verifier:
name: inspec
<% end %>
37 changes: 29 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,19 @@ tty_notify_fail = printf "\033[1;49;91m$(PROJECT_NAME) $(1) failed\033[0m\n"
ifeq ($(has_inotify),Ok)
exec_notify = \
( $(1) \
&& $(call tty_notify_ok,$(2)) && $(call notify_ok,$(2)) \
|| ( $(call tty_notify_fail,$(2)) && $(call notify_fail,$(2)); false ) )
&& $(call tty_notify_ok,"$(2)") && $(call notify_ok,"$(2)") \
|| ( \
$(call tty_notify_fail,"$(2)") && $(call notify_fail,"$(2)"); \
false ) )
else
exec_notify = \
( $(1) \
&& $(call tty_notify_ok,$(2)) || ( $(call tty_notify_fail,$(2)); false ) )
&& $(call tty_notify_ok,"$(2)") \
|| ( $(call tty_notify_fail,"$(2)"); false ) )
endif

define make_notify
$(call exec_notify,$(MAKE) --no-print-directory $(1),$(2))
$(call exec_notify,$(MAKE) --no-print-directory $(1),"$(2)")
endef

.%.png: .%.svg
Expand Down Expand Up @@ -393,6 +396,9 @@ else
endif
touch .acl_build

ansible_check: bundle ## Run kitchen converge with Ansible in check mode
@$(call docker_run,${WRITABLE_VOLUMES_ARGS} --env=ANSIBLE_CHECK_MODE=1,bundle exec kitchen converge)

build: .build ## Build project container
.build: Dockerfile .bash_profile
docker build --rm $(BUILD_OPTS) $(BUILD_ARGS) -t $(DOCKER_BUILD_TAG) \
Expand Down Expand Up @@ -520,18 +526,33 @@ test-dind: .build .acl_build ## Run 'docker run hello-world' within image

test: MAKEFLAGS =
test: .build .acl_build ## Test (CI)
@+$(call make_notify,info,info) && \
$(call make_notify,test-dind,test-dind) && \
$(call make_notify,kitchen,kitchen)
@+$(call make_notify,info,'Docker info') && \
$(call make_notify,test-dind,'Docker-in-Docker') && \
$(call make_notify,bundle,'Bundle') && \
$(call make_notify,ansible_check,'Ansible check') && \
$(call make_notify,kitchen,'Kitchen test')

lxctest: ## Test (CI) with LXC (without Docker-in-Docker)
@$(call exec_notify,GEM_HOME=$(OLD_GEM_HOME) \
GEM_PATH=$(OLD_GEM_PATH) \
GEM_ROOT=$(OLD_GEM_ROOT) \
PATH=$(OLD_PATH) \
bundle install,'Bundle') && \
$(call exec_notify,GEM_HOME=$(OLD_GEM_HOME) \
ANSIBLE_CHECK_MODE=1 \
GEM_PATH=$(OLD_GEM_PATH) \
GEM_ROOT=$(OLD_GEM_ROOT) \
KITCHEN_PROVIDER=vagrant \
PATH=$(OLD_PATH) \
VAGRANT_DEFAULT_PROVIDER=lxc \
bundle exec kitchen converge,'LXC Ansible check') && \
$(call exec_notify,GEM_HOME=$(OLD_GEM_HOME) \
GEM_PATH=$(OLD_GEM_PATH) \
GEM_ROOT=$(OLD_GEM_ROOT) \
KITCHEN_PROVIDER=vagrant \
bundle exec kitchen test,lxctest)
PATH=$(OLD_PATH) \
VAGRANT_DEFAULT_PROVIDER=lxc \
bundle exec kitchen test,'LXC Kitchen test')

usershell: .bundle_build .build .acl_build ## Run user shell
@$(call docker_run,-it --env SHELL=/bin/bash $(RC_ENV_VARS),/bin/bash --login)
6 changes: 3 additions & 3 deletions site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

tasks:
- debug:
var: ansible_ssh_user
- debug:
var: ansible_fqdn
msg:
ansible_ssh_user: "{{ ansible_ssh_user }}"
hostvars__inventory_hostname: "{{ hostvars[inventory_hostname] }}"
...

0 comments on commit 9ba41e4

Please sign in to comment.