Install puppet onto EC2 instance via Elastic Beanstalk .ebextensions
Here's how we install puppet onto our EC2 instances using ELB customizations through .ebextensions. Certain details omitted for the sake of security. I've been unable to make an AMI that contains a preinstalled version of puppet. Each time the instance gets provisioned onto a sever, the environment and certname are out of sync and never seem to get updated.
$CHIRPIFY_ENV
is an ENV variable that gets introduced via the ELB configuration.
# Install puppet agent onto the EC2 instance.
# NOTE the path for elasticbeanstalk variables changes between ELB
# applications. Newer versions of pre-packaged ELB applications have entirely
# different paths, so the following directives are not necessarily compatible
# i.e. /opt/elasticbeanstalk/containerfiles/envars.d
100-install-puppet:
command: /usr/bin/curl -k https://your-puppet-master.com:8140/packages/current/install.bash | bash
test: "[ ! -e /usr/local/bin/puppet ]"
105-puppet-certname:
command: source /opt/elasticbeanstalk/containerfiles/envvars.d/sysenv && /usr/local/bin/puppet config set certname "frontend-$CHIRPIFY_ENV-`hostname -f`" --section agent && /usr/local/bin/puppet config set certname "frontend-$CHIRPIFY_ENV-`hostname -f`" --section main
110-puppet-environment-main:
command: source /opt/elasticbeanstalk/containerfiles/envvars.d/sysenv && /usr/local/bin/puppet config set environment "$CHIRPIFY_ENV" --section agent && /usr/local/bin/puppet config set environment "$CHIRPIFY_ENV" --section main
120-puppet-hosts:
command: /bin/echo "{ip-of-puppet-master} puppet pe-puppet my.puppetserver.com" >> /etc/hosts
test: '! grep -q "my.puppetserver.com" /etc/hosts'
130-puppet-run:
command: /usr/local/bin/puppet agent --test --waitforcert 1m
ignoreErrors: true