diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e6017af..22e281c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/make/ansible.mk b/make/ansible.mk new file mode 100644 index 0000000..5244b75 --- /dev/null +++ b/make/ansible.mk @@ -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 diff --git a/make/include.mk b/make/include.mk index cf95f4d..3f469ae 100644 --- a/make/include.mk +++ b/make/include.mk @@ -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 # diff --git a/tests/outputs/ansible-provision-tag.txt b/tests/outputs/ansible-provision-tag.txt new file mode 100644 index 0000000..4ee9ba4 --- /dev/null +++ b/tests/outputs/ansible-provision-tag.txt @@ -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" diff --git a/tests/outputs/ansible-provision.txt b/tests/outputs/ansible-provision.txt new file mode 100644 index 0000000..895e554 --- /dev/null +++ b/tests/outputs/ansible-provision.txt @@ -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 diff --git a/tests/tests.sh b/tests/tests.sh index 02cc9b7..5dfffb9 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -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 ] @@ -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/ *$//') diff --git a/update.sh b/update.sh index cc92ee5..a4213f3 100755 --- a/update.sh +++ b/update.sh @@ -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 @@ -36,6 +36,7 @@ declare -a files=( "lagoon.mk" "qa.mk" "kubectl.mk" + "ansible.mk" ) declare -a remove_files=(