Created
April 23, 2019 05:55
-
-
Save guyc/8355e72722b254107f5d68203f87dd0d to your computer and use it in GitHub Desktop.
Encode a bash file into base64 cloudinit user data.
This file contains hidden or 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
#!./env/bin/python | |
import base64 | |
import sys | |
def encode_user_data(lines): | |
""" | |
Input is an array of lines that together make a script. | |
Output is a base64 encoded block suitable for the userdata parameter | |
of an instance config. | |
""" | |
cloud_config = "#cloud-config\nruncmd:\n" + ''.join([f" - {line}" for line in lines]) | |
return base64.b64encode(cloud_config.encode("utf-8")).decode('ascii') | |
if __name__ == "__main__": | |
print(encode_user_data(sys.stdin.readlines())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment