Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/event_source_aws_cloudtrail/runme.sh

raw
1 #!/usr/bin/env bash
2 #
3 # Beware: most of our tests here are run in parallel.
4 # To add new tests you'll need to add a new host to the inventory and a matching
5 # '{{ inventory_hostname }}'.yml file in roles/ec2_instance/tasks/
6
7
8 set -eux
9
10 export ANSIBLE_ROLES_PATH=../
11
12 CMD_ARGS=("$@")
13 # For ansible-rulebook --vars: pass only the var file path (e.g. after -e), not "-e $'@...'"
14 if [[ ${#CMD_ARGS[@]} -ge 2 && "${CMD_ARGS[0]}" == "-e" ]]; then
15 VAR_FILE="${CMD_ARGS[1]}"
16 # Strip $'@ prefix and trailing ' (e.g. $'@/path/to/file.json' -> /path/to/file.json)
17 VAR_FILE="${VAR_FILE#@}"
18 fi
19
20 # Create the temp directory
21 TEMP_DIR=$(mktemp -d -t event_source_aws_cloudtrail_vars)
22
23 # Set a 'trap' to remove the directory when the script exits
24 trap 'rm -rf "$TEMP_DIR"' EXIT
25
26 # join the var file and the vars.json file
27 jq -s 'add' "${VAR_FILE}" vars.json > "$TEMP_DIR/vars.json"
28
29 ansible-rulebook --inventory inventory --rulebook rulebooks/aws_manage_cloudtrail_ec2_keypair.yml --vars "$TEMP_DIR/vars.json" &
30
31 # sleep 10 seconds for make sure ansible-rulebook had no errors
32 sleep 10
33
34 ansible-playbook ec2_keypair.yml -i inventory -e "@$TEMP_DIR/vars.json"