-
-
Save jonathan-kosgei/9953632e5ec87992e2dc85fab71ff01f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
def customgrains(): | |
# initialize a grains dictionary | |
grains = {} | |
awsinstanceid = os.system("""`wget -qO- http://instance-data/latest/meta-data/instance-id`""") | |
awsregion = os.system("""`wget -qO- http://instance-data/latest/meta-data/placement/availability-zone | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:' | echo`""") | |
awsvpc = os.system("""`aws ec2 describe-tags --filters "Name=resource-id,Values="""+str(awsinstanceid)+"""" "Name=key,Values=VPC" --region """+str(awsregion)+""" --query 'Tags[*].Value' --output text`""") | |
kubemaster = os.system("""`aws ec2 describe-instances --region="""+str(awsregion)+""" --filters Name=tag:Name,Values="""+str(awsvpc)+""".kubemaster* --query 'Reservations[*].Instances[*].NetworkInterfaces[*].PrivateIpAddress' --output text | tail`""") | |
grains['kubemaster'] = kubemaster | |
grains['etcdauthority'] = str(kubemaster)+":6666" | |
return grains |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment