Skip to content

Instantly share code, notes, and snippets.

@scottharwell
Created September 30, 2021 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottharwell/726288ffc633bc2e863c59dbd971e831 to your computer and use it in GitHub Desktop.
Save scottharwell/726288ffc633bc2e863c59dbd971e831 to your computer and use it in GitHub Desktop.
Hook for Ansible projects that require a `yamllint` and `ansible-lint` check before any commit.
#!/usr/bin/env bash
# Run yamllint first to ensure that code passes checks
yamllint .
YAML_LINT=$?
# Go ahead and stop if yamllint fails since ansible-lint takes a while
if [ $YAML_LINT == 1 ]; then
exit 1
fi
# Run ansible-lint to ensure ansible checks
ansible-lint
ANSIBLE_LINT=$?
EXIT_CODE=$(($YAML_LINT + $ANSIBLE_LINT))
exit $EXIT_CODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment