-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·51 lines (40 loc) · 1.29 KB
/
bootstrap.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
#!/bin/sh
export ASSUME_ALWAYS_YES='true'
export PKG='/usr/local/sbin/pkg'
# disable ssh client hostkey check
export ANSIBLE_HOST_KEY_CHECKING='False'
# bootstrap pkg
/usr/sbin/pkg bootstrap
$PKG update
$PKG upgrade
$PKG audit -Fq
# bootstrap requirements
$PKG install \
devel/py-pip \
sysutils/ansible \
security/openssh-askpass \
security/sshpass \
shells/bash
# configure inventory
[ ! -d /usr/local/etc/ansible ] && mkdir -p /usr/local/etc/ansible
if [ ! -f /usr/local/etc/ansible/hosts ]; then
cp /usr/local/share/examples/ansible/ansible.cfg /usr/local/etc/ansible/ansible.cfg
cat <<EOF > /usr/local/etc/ansible/hosts
[freebsd]
`hostname -f`
[freebsd:vars]
ansible_python_interpreter=/usr/local/bin/python2
EOF
sed -i.old 's,^#\(inventory.*\),\1,p' /usr/local/etc/ansible/ansible.cfg
else
cp /usr/local/etc/ansible/hosts /usr/local/etc/ansible/hosts.old
fi
# configure filter plugin
[ ! -d /usr/local/share/ansible/plugins/filter ] && mkdir -p /usr/local/share/ansible/plugins/filter
cp plugins/filter/pkg_exclude.py /usr/local/share/ansible/plugins/filter/
# list target hosts
ansible --list-hosts all
echo "[*] Run ansible-playbook now!"
echo " > sudo ansible-playbook -b -k -u $SUDO_USER -v playbooks/laptop.yml"
# ping hosts
ansible all -m ping -b -k -u $SUDO_USER