-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathans_play_tasks
More file actions
executable file
·42 lines (30 loc) · 822 Bytes
/
ans_play_tasks
File metadata and controls
executable file
·42 lines (30 loc) · 822 Bytes
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
40
41
#!/usr/bin/env bash
[[ -z "${1}" ]] && { echo "${0} host_name task1_file task2_file .."; exit; }
TGT="${1}"
shift
cd "${HOME}/ansible/playbooks" || exit 1
echo "Running tasks on target: ${TGT}"
NOW="$(date +%Y%m%d_%H%M%S)"
PBOOK_TMP="${TGT}_play_tmp_${NOW}.yml"
cat > "${PBOOK_TMP}" <<EOF
---
- hosts: "{{ target }}"
tasks:
EOF
declare -a ARGS
read -ra ARGS <<< "${@}"
declare -a task_list
for i in "${ARGS[@]}"; do
if [[ -f "${i}" ]]; then
task_list+=("${i}")
echo " - include_tasks: ${i}" >> "${PBOOK_TMP}"
elif [[ -f "tasks/${i}" ]]; then
task_list+=("${i}")
echo " - include_tasks: tasks/${i}" >> "${PBOOK_TMP}"
fi
done
for task in "${task_list[@]}"; do
ARGS=( "${ARGS[@]/${task}/}" )
done
ans_play ${TGT} ${ARGS[@]} ${PBOOK_TMP}
[[ -e "${PBOOK_TMP}" ]] && rm -f "${PBOOK_TMP}"