blob: 242f1842f58c8fd4232735e2fe2d11020026f71e (
plain)
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
|
#!/bin/sh
#
# Copyright (c) 2018 Aaron LI
# MIT License
#
# 2018-01-25
#
ROOTDIR="${0%/*}"
PLAYBOOK="${ROOTDIR}/bootstrap.yml"
echo "Playbook directory: ${ROOTDIR}"
echo "Playbook: ${PLAYBOOK}"
SSHDIR="${ROOTDIR}/private/ssh"
SSHKEY="${SSHDIR}/ansible.key"
if [ -f "${SSHKEY}" ]; then
echo "ERROR: SSH key already exists: ${SSHKEY}"
echo "Target machine already been bootstrapped?"
else
[ ! -d "${SSHDIR}" ] && mkdir -v "${SSHDIR}"
echo "Generating SSH key ..."
ssh-keygen -t ed25519 -C "ansible" -f "${SSHKEY}"
echo "Generated SSH key: ${SSHKEY}"
echo "Bootstrap target by installing Python ..."
ansible vultr -u root \
-m raw -a "pkg update; pkg install -y python3"
ansible-playbook \
--verbose --diff \
--ask-pass --ask-become-pass \
"${PLAYBOOK}"
echo "Bootstrapped the target machine!"
ansible vultr -u ansible -m ping
ansible vultr -u ansible -m command -a whoami
ansible vultr -u ansible -m command -a whoami -b
fi
|