-
Notifications
You must be signed in to change notification settings - Fork 2
/
init-ansible-project.sh
executable file
·80 lines (54 loc) · 1.49 KB
/
init-ansible-project.sh
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
#!/bin/bash
PROGNAME=$(basename $0)
LANG=
PROJECTPATH=$1
if test -z "$PROJECTPATH"; then
echo "Usage: $PROGNAME <PROJECTPATH>" 1>&2
exit 1
fi
if test -e "$PROJECTPATH"; then
echo "$PROGNAME: directory '$PROJECTPATH' already exists" 1>&2
exit 2
fi
get_abs_path() {
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}
SCRIPT_ABS_PATH=$(get_abs_path $0)
mkdir -vp $PROJECTPATH
pushd $PROJECTPATH >/dev/null
for d in playbooks {group,host}_vars roles; do
mkdir -v $d
done
function write_out() {
sed -rn -e '/^={20}[[:space:]]*'"$1"'/,/={20}/p' $SCRIPT_ABS_PATH |
sed -r -e 1d -e '$d' \
>$1
echo "$PROGNAME: created '$1'"
}
for f in ansible.cfg .envrc inventory; do
write_out $f
done
exit 0
==================== ansible.cfg ====================
[defaults]
inventory = ./inventory
stdout_callback = yaml
gathering = smart
fact_caching = jsonfile
fact_caching_connection = ~/.ansible/fact_cache
fact_caching_timeout = 86400
retry_files_enabled = yes
retry_files_save_path = ~/.ansible/retry-files
force_handlers = true
nocows = true
roles_path = ./roles
ansible_managed = "Managed by ansible, don't make changes here!"
[ssh_connection]
#pipelining = true
==================== .envrc ====================
export ANSIBLE_CONFIG=$(expand_path ansible.cfg)
==================== inventory ====================
[all:vars]
ansible_python_interpreter=/usr/bin/python3
ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
====================