File: ansible_playbook_check.sh

package info (click to toggle)
scap-security-guide 0.1.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 110,644 kB
  • sloc: xml: 241,883; sh: 73,777; python: 32,527; makefile: 27
file content (39 lines) | stat: -rwxr-xr-x 898 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

# tries to find playbooks
# The fourth parameter, when provided, is the product name.
find_glob=
if [[ $1 =~ ansible-playbook ]]; then
	find_glob="${3}-playbook-*.yml"
elif [[ $1 =~ ansible-lint ]]; then
	find_glob="${4:-}*.yml"
elif [[ $1 =~ yamllint ]]; then
	find_glob="${4:-}*.yml"
else
	echo "Error: '$1' is not expected executable" 1>&2
	exit 1
fi

cd "$2" || exit 1

readarray -t playbooks < <(find . -type f -name "${find_glob}")

# Scripts main purpose
# If no playbooks exist at all, then test is okay.
if (( ${#playbooks[@]} == 0 )); then
	echo "$2 does not contain any valid YAML files. Skipping the test."
	exit 0
fi

if [[ $1 =~ ansible-playbook ]]; then
	"$1" --syntax-check "${3}"-playbook-*.yml
	ret=$?
elif [[ $1 =~ ansible-lint ]]; then
	"$1" -c "$3" -p "${playbooks[@]}"
	ret=$?
elif [[ $1 =~ yamllint ]]; then
	"$1" -c "$3" "${playbooks[@]}"
	ret=$?
fi

exit $ret