This repository has been archived on 2024-03-13. You can view files and clone it, but cannot push or open issues or pull requests.
2022-02-10 02:46:01 +00:00
|
|
|
#
|
|
|
|
# Day 3 - Generate Inventory (Phase 1: tachyon user)
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# 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 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
|
2022-02-10 23:35:07 +00:00
|
|
|
|
|
|
|
[ssh_connection]
|
|
|
|
ssh_args = "-o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey"
|
|
|
|
pipelining = true
|
2022-02-10 02:46:01 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
ansible "$CATEGORY" -m ping
|