From 01a45b43d48e85d45df6d12cec79173fa6f37d1c Mon Sep 17 00:00:00 2001 From: Skydust Date: Sun, 8 Dec 2024 11:57:56 +0100 Subject: [PATCH] Using bash and supported inventories --- Dockerfile | 4 ++-- action.yml | 3 +++ entrypoint.sh | 18 +++++++++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index dd70e17..057eb4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM public.ecr.aws/docker/library/node:22-alpine3.20 ENV PATH=/root/.local/bin:$PATH # Install git for gitea actions and ansible -RUN apk add --no-cache bash curl python3 pipx git rsync unzip openssh +RUN apk add --no-cache bash curl python3 pipx git rsync unzip openssh bash RUN pipx install --include-deps ansible ENV PY_COLOR="1" @@ -14,4 +14,4 @@ WORKDIR /usr/src COPY entrypoint.sh . RUN chmod +x /usr/src/entrypoint.sh -ENTRYPOINT ["ash","-c","/usr/src/entrypoint.sh"] +ENTRYPOINT ["bash","-c","/usr/src/entrypoint.sh"] diff --git a/action.yml b/action.yml index 437f429..588c3be 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,9 @@ inputs: playbook: description: The playbook's path required: true + inventory: + description: Comma separated inventory files + required: false only_check: description: Whether to only check without changes required: false diff --git a/entrypoint.sh b/entrypoint.sh index 901335f..32e63b1 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,17 +1,25 @@ -#!/usr/bin/env ash +#!/usr/bin/env bash INPUT_PLAYBOOK_PATH="$playbook" INPUT_ONLY_CHECK="$only_check" +INPUT_INVENTORY_FILE="$inventory" set -e -ANSIBLE_OPTIONS="-vv" +ANSIBLE_OPTIONS=("-vv") if [ "$INPUT_ONLY_CHECK" = "true" ]; then - ANSIBLE_OPTIONS="${ANSIBLE_OPTIONS} --check --diff" + ANSIBLE_OPTIONS+=("--check" "--diff") fi; -echo "Running playbook with options: ansible-playbook $ANSIBLE_OPTIONS \"$INPUT_PLAYBOOK_PATH\"" -ansible-playbook $ANSIBLE_OPTIONS "$INPUT_PLAYBOOK_PATH" +IFS=',' read -r -a inventories <<< "$INPUT_INVENTORY_FILE" +for inv in "${inventories[@]}"; do + ANSIBLE_OPTIONS+=("--inventory" "$inv") +done + +ANSIBLE_OPTIONS+=("$INPUT_PLAYBOOK_PATH") + +echo "Running playbook with options: ansible-playbook ${ANSIBLE_OPTIONS[*]}" +ansible-playbook "${ANSIBLE_OPTIONS[@]}" exit 0