Configsets

Configsets are essentially configuration management. Use configsets to configure and update your EC2 instances automatically. Lono allows you to use configsets in a reusable way.

Configuration Management Tool

There are several configuration management tools out there: chef, puppet, ansible, salt, configsets. They all perform these 3 steps:

  1. Install a package
  2. Configure it
  3. Run it as a Service

Configset Example

Here’s a simple configset example in DSL form.

app/configsets/httpd/lib/configset.rb:

package("yum",
  httpd: []
)
file("/var/www/html/index.html",
  content: "<h2>html test content</h2>"
)
service("sysvinit",
  httpd: {
    enabled: true,
    ensureRunning: true,
  }
)

The configet can also be written in ERB form.

app/configsets/httpd/lib/configset.yml:

AWS::CloudFormation::Init:
  config:
    packages:
      yum:
        httpd: []
    files:
      "/var/www/html/index.html":
        content: "<h2>html test content</h2>"
    services:
      sysvinit:
        httpd:
          enabled: true
          ensureRunning: true

This configset will install, configure, and ensure that the httpd server is running, even if the server is rebooted.

Usage

Your project configsets are located in the app/configsets. Example:

  • app/configsets/cfn-hup/lib/configset.rb
  • app/configsets/httpd/lib/configset.rb

You tell lono to add them to CloudFormation templates with configs. Example:

configs/ec2/configsets/base.rb:

configset("cfn-hup", resource: "Instance")
configset("httpd", resource: "Instance")

This installs cfn-hup and httpd on the EC2 instance.

More specifically, lono injects the 2 configsets to the CloudFormation template resource with the logical id Instance. The cfn-hup and httpd configsets are added to the Instance.Metadata.AWS::CloudFormation::Init attribute.

You have full control over which configsets to use for each template.

How They Work

Configsets do not magically get applied after being added to the CloudFormation template though. The cfn-init script must be called to apply the configset. Usually the cfn-init script is called in the UserData script. This ensures configsets are applied when instances are launched. Additionally, the cfn-hup script can be set up to apply configsets continuously.

UserData cfn-init

You can make sure configsets are applied when instances are launched by calling the cfn-init script in UserData. Here’s an example UserData script.

#!/bin/bash
yum install -y aws-cfn-bootstrap # install cfn-init
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource Instance --region ${AWS::Region}

The ${AWS::StackName} and ${AWS::Region} will be substituted for their actual values at CloudFormation runtime. The --resource Instance specifies which resource to add the configsets to.

Note: On AmazonLinux2 cfn-init is already installed.

Configsets ultimately work with cfn-init and AWS::CloudFormation::Init. The Lono configsets concept empowers you to reuse configsets.

Pro tip: Use the <- and -> arrow keys to move back and forward.

Edit this page

See a typo or an error? You can improve this page. This website is available on GitHub and contributions are encouraged and welcomed. We love pull requests from you!