Skip to content

Commit

Permalink
ci: set up ansible on separate script
Browse files Browse the repository at this point in the history
  • Loading branch information
DavSanchez committed Feb 16, 2024
1 parent 1aa1e19 commit e74bfb8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
12 changes: 8 additions & 4 deletions test/Ansible.common
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
ANSIBLE_FOLDER ?= $(CURDIR)
REQUIREMENTS_FILE ?= $(ANSIBLE_FOLDER)/requirements.yml

ROLES_PATH:=$(ANSIBLE_FOLDER)/roles
COLLECTIONS_PATH:=$(ANSIBLE_FOLDER)/collections
export REQUIREMENTS_FILE ?= $(ANSIBLE_FOLDER)/requirements.yml
export ROLES_PATH:=$(ANSIBLE_FOLDER)/roles
export COLLECTIONS_PATH:=$(ANSIBLE_FOLDER)/collections
export CROWDSTRIKE_ROLE_PULL_KEY := $(HOME)/.ssh/crowdstrike_ansible_role_key

$(ROLES_PATH) $(COLLECTIONS_PATH):
@mkdir -p $@

.PHONY: ansible/dependencies
ansible/dependencies: $(ROLES_PATH) $(COLLECTIONS_PATH)
ifdef ANSIBLE_ENV_SCRIPT
sh $(ANSIBLE_ENV_SCRIPT)
else
ansible-galaxy role install -r $(REQUIREMENTS_FILE) -p $(ROLES_PATH)
ansible-galaxy collection install -r $(REQUIREMENTS_FILE) -p $(COLLECTIONS_PATH)
endif

.PHONY: ansible/clean
ansible/clean:
Expand Down
2 changes: 1 addition & 1 deletion test/provision/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ endif

.PHONY: provision
provision: terraform/backend
$(MAKE) ansible/dependencies ANSIBLE_FOLDER=$(ANSIBLE_FOLDER)
$(MAKE) ansible/dependencies ANSIBLE_FOLDER=$(ANSIBLE_FOLDER) ANSIBLE_ENV_SCRIPT=$(ANSIBLE_FOLDER)/set_ansible_env.sh
terraform -chdir=$(TERRAFORM_DIR) init -reconfigure && \
terraform -chdir=$(TERRAFORM_DIR) apply -auto-approve

Expand Down
16 changes: 16 additions & 0 deletions test/provision/terraform/set_ansible_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

# Setting up SSH for pulling private roles
echo "Setting up SSH for pulling private roles"

eval "$(ssh-agent -s)"

if ssh-add "$CROWDSTRIKE_ROLE_PULL_KEY"; then
echo "Added SSH key at ${CROWDSTRIKE_ROLE_PULL_KEY}"
else
echo "No additional ssh identities added"
fi

echo "Setting up Ansible environment"
ansible-galaxy role install -r "${REQUIREMENTS_FILE}" -p "${ROLES_PATH}"
ansible-galaxy collection install -r "${REQUIREMENTS_FILE}" -p "${COLLECTIONS_PATH}"

0 comments on commit e74bfb8

Please sign in to comment.