day one script: generate ansible inventory/config and ping the node
This commit is contained in:
parent
b66f1bcadd
commit
0e95423877
|
@ -0,0 +1,29 @@
|
|||
#
|
||||
# Day 1 - Generate Inventory
|
||||
# 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
|
||||
|
||||
# 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=root
|
||||
EOF
|
||||
|
||||
# create or clobber hosts file
|
||||
cat > ansible.cfg << EOF
|
||||
[defaults]
|
||||
inventory = $(pwd)/hosts
|
||||
EOF
|
||||
|
||||
ansible "$CATEGORY" -m ping
|
||||
|
Reference in New Issue