Method: CloudFormationTool::CloudInit#encode

Defined in:
lib/cloud_formation_tool/cloud_init.rb

#encode(allow_gzip = true) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cloud_formation_tool/cloud_init.rb', line 45

def encode(allow_gzip = true)
  yamlout = compile
  usegzip = false
  if allow_gzip and yamlout.size > $MAX_USER_DATA_SIZE # max AWS EC2 user data size - try compressing it
    yamlout = Zlib::Deflate.new(nil, 31).deflate(yamlout, Zlib::FINISH) # 31 is the magic word to have deflate create a gzip compatible header
    usegzip = true
  end
  if yamlout.size > $MAX_USER_DATA_SIZE # still to big, we should upload to S3 and create an include file
    url = upload  make_filename('init'),
                  yamlout, mime_type: 'text/cloud-config', gzip: usegzip
    log "Wrote cloud config to #{url}"
    [ "#include", url ].join "\n"  
  else
    yamlout
  end
end