Skip to content

Instantly share code, notes, and snippets.

@scottharwell
Created September 30, 2021 00:10
Show Gist options
  • Select an option

  • Save scottharwell/726288ffc633bc2e863c59dbd971e831 to your computer and use it in GitHub Desktop.

Select an option

Save scottharwell/726288ffc633bc2e863c59dbd971e831 to your computer and use it in GitHub Desktop.

Revisions

  1. scottharwell created this gist Sep 30, 2021.
    18 changes: 18 additions & 0 deletions Ansible Project Precommit Hook.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #!/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