Skip to content

Commit

Permalink
Merge pull request #14 from druidfi/ansible
Browse files Browse the repository at this point in the history
Add ansible
  • Loading branch information
back-2-95 committed Dec 19, 2023
2 parents 305fe1f + a5172a2 commit 06bdd72
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:

- name: Test that downloaded files exist in debug folder
run: |
test -f debug/tools/make/ansible.mk
test -f debug/tools/make/lagoon.mk
test -f debug/tools/make/common.mk
test -f debug/tools/make/composer.mk
Expand Down
38 changes: 38 additions & 0 deletions make/ansible.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
ANSIBLE_INVENTORY_PATH ?= ansible/inventory
ANSIBLE_ROLES_PATH ?= ansible/roles
ANSIBLE_CHECK_ROLE ?= geerlingguy.docker
ANSIBLE_PLAYBOOK ?= ansible-playbook
ANSIBLE_PROVISION ?= ansible/provision.yml
ANSIBLE_REQUIREMENTS ?= ansible/requirements.yml

PHONY += provision
provision: INVENTORY ?= production
provision: $(ANSIBLE_ROLES_PATH)/$(ANSIBLE_CHECK_ROLE) ## Make provisioning
$(call step,Ansible: Make dry run on provisioning...\n)
@$(ANSIBLE_PLAYBOOK) -i $(ANSIBLE_INVENTORY_PATH)/$(INVENTORY) $(ANSIBLE_PROVISION)

PHONY += provision-%
provision-%: INVENTORY ?= production
provision-%: $(ANSIBLE_ROLES_PATH)/$(ANSIBLE_CHECK_ROLE) ## Make provisioning by tag
$(call step,Ansible: Make provisioning by tag "$*"...\n)
@$(ANSIBLE_PLAYBOOK) -i $(ANSIBLE_INVENTORY_PATH)/$(INVENTORY) $(ANSIBLE_PROVISION) --tags="$*"

PHONY += provision-dry-run
provision-dry-run: INVENTORY ?= production
provision-dry-run: $(ANSIBLE_ROLES_PATH)/$(ANSIBLE_CHECK_ROLE) ## Make dry run on provisioning
$(call step,Ansible: Make dry run on provisioning...\n)
@$(ANSIBLE_PLAYBOOK) -i $(ANSIBLE_INVENTORY_PATH)/$(INVENTORY) $(ANSIBLE_PROVISION) --check

PHONY += ansible-install-roles
ansible-install-roles: ## Install Ansible roles
$(call step,Ansible: Install Ansible roles...\n)
@ansible-galaxy install -r $(ANSIBLE_REQUIREMENTS) -p $(ANSIBLE_ROLES_PATH)

PHONY += ansible-update-roles
ansible-update-roles: ## Update Ansible roles
$(call step,Ansible: Update Ansible roles...\n)
@ansible-galaxy remove --roles-path=$(ANSIBLE_ROLES_PATH) $(shell find $(ANSIBLE_ROLES_PATH) -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) || true
@ansible-galaxy install --force-with-deps --role-file=$(ANSIBLE_REQUIREMENTS) --roles-path=$(ANSIBLE_ROLES_PATH)

$(ANSIBLE_ROLES_PATH)/$(ANSIBLE_CHECK_ROLE):
@$(MAKE) ansible-install-roles
10 changes: 10 additions & 0 deletions make/include.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ ifeq ($(IS_SYMFONY),yes)
include $(DRUIDFI_TOOLS_MAKE_DIR)symfony.mk
endif

#
# Other tools
#

HAS_ANSIBLE ?= $(shell test -d ansible && echo yes || echo no)

ifeq ($(HAS_ANSIBLE),yes)
include $(DRUIDFI_TOOLS_MAKE_DIR)ansible.mk
endif

#
# Hosting systems
#
Expand Down
7 changes: 7 additions & 0 deletions tests/outputs/ansible-provision-tag.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
provision-foobar HAS_ANSIBLE=yes
---
__MAKE__ ansible-install-roles
printf "\n⭐ \033[0;33mAnsible: Install Ansible roles...\n\033[0m\n"
ansible-galaxy install -r ansible/requirements.yml -p ansible/roles
printf "\n⭐ \033[0;33mAnsible: Make provisioning by tag "foobar"...\n\033[0m\n"
ansible-playbook -i ansible/inventory/production ansible/provision.yml --tags="foobar"
7 changes: 7 additions & 0 deletions tests/outputs/ansible-provision.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
provision HAS_ANSIBLE=yes
---
__MAKE__ ansible-install-roles
printf "\n⭐ \033[0;33mAnsible: Install Ansible roles...\n\033[0m\n"
ansible-galaxy install -r ansible/requirements.yml -p ansible/roles
printf "\n⭐ \033[0;33mAnsible: Make dry run on provisioning...\n\033[0m\n"
ansible-playbook -i ansible/inventory/production ansible/provision.yml
11 changes: 9 additions & 2 deletions tests/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

OS=$(uname -s)

if [ "${OS}" == "Linux" ]
if [ "${OS}" == "Darwin" ]
then

echo "Running on ${OS}"
MAKE=$(xcode-select -p)/usr/bin/make

else

MAKE=make

fi

printf "Running on ${OS} with make at ${MAKE}\n\n"

NODE_VERSION=$(command -v node > /dev/null && node --version | cut -c2-3)

if [ "${NODE_VERSION}" != 20 ]
Expand All @@ -33,6 +39,7 @@ do

EXPECTED=${EXPECTED/__PWD__/$(pwd)}
EXPECTED=${EXPECTED/__HOME__/$(echo $HOME)}
EXPECTED=${EXPECTED/__MAKE__/$(echo $MAKE)}

OUTPUT=$(make -n --no-print-directory --directory=make ${MAKE_TARGET} | sed 's/^ *//;s/ *$//')

Expand Down
3 changes: 2 additions & 1 deletion update.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

VERSION=2023-09-09-20-17
VERSION=2023-12-19-08-35
DEBUG=0
GITHUB=https://raw.githubusercontent.com
REPOSITORY=druidfi/tools
Expand Down Expand Up @@ -36,6 +36,7 @@ declare -a files=(
"lagoon.mk"
"qa.mk"
"kubectl.mk"
"ansible.mk"
)

declare -a remove_files=(
Expand Down

0 comments on commit 06bdd72

Please sign in to comment.