Day three: enhance SSH security in two separate phases. Closes #3
This commit is contained in:
parent
198242e1d5
commit
197ac5d0ef
4 changed files with 166 additions and 0 deletions
44
day3_geninventory_phase2.sh
Executable file
44
day3_geninventory_phase2.sh
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#
|
||||
# Day 3 - Generate Inventory (Phase 2: tachyon user on obscure port)
|
||||
# Requires linode-cli to be installed (`pip3 install linode-cli`)
|
||||
# The hosts file generated requires ansible (`pip3 install ansible`)
|
||||
# This will crush any ansible.cfg and hosts files in the current directory.
|
||||
|
||||
# Default ansible group and linode label
|
||||
if [ -z "$CATEGORY" ]
|
||||
then
|
||||
CATEGORY="UpskillChallengeNode"
|
||||
fi
|
||||
|
||||
if [ -z "$ADMINUSER" ]
|
||||
then
|
||||
ADMINUSER="tachyon"
|
||||
fi
|
||||
|
||||
if [ -z "$NODESSHPORT" ]
|
||||
then
|
||||
NODESSHPORT=22022
|
||||
fi
|
||||
|
||||
# fetch IP address from Linode. Assumes one device (TODO: handle a swarm of them).
|
||||
NODEIP=$(linode-cli linodes list --format 'ipv4' --label "$CATEGORY" --text | tail -n 1)
|
||||
|
||||
# create or clobber hosts file
|
||||
cat > hosts << EOF
|
||||
[$CATEGORY]
|
||||
$NODEIP:$NODESSHPORT ansible_user=$ADMINUSER
|
||||
|
||||
[$CATEGORY:vars]
|
||||
ansible_ssh_user=$ADMINUSER
|
||||
ansible_become=yes
|
||||
ansible_become_user=root
|
||||
ansible_become_method=sudo
|
||||
EOF
|
||||
|
||||
# create or clobber hosts file
|
||||
cat > ansible.cfg << EOF
|
||||
[defaults]
|
||||
inventory = $(pwd)/hosts
|
||||
EOF
|
||||
|
||||
ansible "$CATEGORY" -m ping
|
||||
Reference in a new issue