Skip to content

Commit

Permalink
feat: better setup.sh to cover checking
Browse files Browse the repository at this point in the history
This refactor includes the below changes

- Make ansible playbook with the latest collections
- Better setup script to cover ansible playbook checking

Referenced error message:

Unsupported parameters for (community.general.cargo) module: locked.
Supported parameters include: version, name, state, path."}
  • Loading branch information
jeffreytse committed Aug 2, 2024
1 parent 3ddf4bb commit bf83498
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

# Use separate run commands so command status handled correctly on Windows
- name: install ansible
- name: Install ansible
run: pip install ansible
- name: run ansible-playbook check
run: cd ansible && ansible-playbook setup.yml --check

- name: Run ansible-playbook check
run: ./setup.sh --check
2 changes: 2 additions & 0 deletions ansible/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
collections:
- name: community.general
30 changes: 29 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

# Exit immediately if a command exits with a non-zero status
set -e

if ! command -v ansible-playbook &> /dev/null; then
echo "Command ansible-playbook could not be found!"
echo
Expand All @@ -9,4 +12,29 @@ if ! command -v ansible-playbook &> /dev/null; then
exit 1
fi

cd ./ansible && ansible-playbook --ask-become-pass setup.yml
ANSIBLE_PLAYBOOK_ARGS=()

function usage() {
echo "Usage: setup.sh [OPTIONS]"
echo
echo "Options:"
echo ""
echo "--help Show this message and exit"
echo "--check Run the playbook in check mode (default: false)"
exit 0
}

# idiomatic parameter and option handling in sh
while test $# -gt 0; do
case "$1" in
--check) ANSIBLE_PLAYBOOK_ARGS+=("--check");;
--help) usage;;
--*) echo "bad option $1";;
*) usage;;
esac
shift
done

cd ./ansible
ansible-galaxy collection install -r requirements.yml --upgrade
ansible-playbook --ask-become-pass setup.yml ${ANSIBLE_PLAYBOOK_ARGS[@]}

0 comments on commit bf83498

Please sign in to comment.