-
Notifications
You must be signed in to change notification settings - Fork 2
/
ansible-test-play
executable file
·84 lines (67 loc) · 1.68 KB
/
ansible-test-play
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
## Populates $PWD with example ansible-playbook/hosts/settings structure files,
## and utility helpers to ./run ./edit and ./clean these files.
cat > run <<"UPPEREOF"
#!/bin/bash
test_play_wrap="$(basename "$0")"
test_play_dir="$(dirname "$(readlink -f "$0")")"
cd $test_play_dir
TEST_PLAY_FILES="./test-play.yaml ./test-play.settings ./test-play.hosts"
test_play_init() {
set +x
[[ -f test-play.hosts ]] || cat > test-play.hosts <<EOF
[local]
localhost ansible_connection=local
[some-group]
localhost
EOF
[[ -f test-play.settings ]] || cat > test-play.settings <<EOF
---
something: "Hello world"
workarounds:
first:
enabled: false
EOF
[[ -f test-play.yaml ]] || cat > test-play.yaml <<EOF
- hosts: localhost
name: "my test play"
gather_facts: no
sudo: no
tasks:
- debug: msg=hi
register: mytask
- debug: var=something
when: workarounds is defined
# your custom tasks
EOF
echo "You can now MODIFY test-play.{hosts,settings,yaml} files"
echo "(inventory, injected facts, playbook) or use helper:"
echo ""
echo " ./edit"
echo ""
echo "End you can also run these as:"
echo " ansible-playbook -vvvv -i test-play.hosts --extra-vars @test-play.settings test-play.yaml"
echo "or use helper:"
echo ""
echo " ./run"
echo ""
echo "To reset these test-play.* files use: ./clean"
}
test_play_clean() {
rm -f $TEST_PLAY_FILES;
test_play_init
}
test_play_run() {
ansible-playbook -vvvv -i test-play.hosts --extra-vars @test-play.settings test-play.yaml;
}
test_play_edit() {
vim -p $TEST_PLAY_FILES
}
set -x
test_play_${test_play_wrap/.sh}
UPPEREOF
chmod +x ./run
ln -snf ./run init
ln -snf ./run clean
ln -snf ./run edit
./init