From 976bbccc5c22cd8e22563a902e24c489e3431b92 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Thu, 19 Sep 2019 10:11:08 +0800 Subject: bootstrap.sh: Do not generate SSH key if exists Allow to bootstrap host again after reinstallation (for example). --- bootstrap.sh | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'bootstrap.sh') diff --git a/bootstrap.sh b/bootstrap.sh index 242f184..18404f0 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -13,23 +13,21 @@ 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 +if [ ! -f "${SSHKEY}" ]; then [ ! -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 + +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 --become -- cgit v1.2.2