<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nick Bitzer on Medium]]></title>
        <description><![CDATA[Stories by Nick Bitzer on Medium]]></description>
        <link>https://medium.com/@nickbitzer?source=rss-959a278f925------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XTZFLAkrTCKrgqgQ7WFhwA.png</url>
            <title>Stories by Nick Bitzer on Medium</title>
            <link>https://medium.com/@nickbitzer?source=rss-959a278f925------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 10:11:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nickbitzer/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Auto Scaling Jenkins Builders with Packer, Ansible and AWS]]></title>
            <link>https://medium.com/@nickbitzer/auto-scaling-jenkins-builders-with-packer-ansible-and-aws-e84f4d0a3853?source=rss-959a278f925------2</link>
            <guid isPermaLink="false">https://medium.com/p/e84f4d0a3853</guid>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[packers]]></category>
            <dc:creator><![CDATA[Nick Bitzer]]></dc:creator>
            <pubDate>Thu, 09 Mar 2017 00:44:31 GMT</pubDate>
            <atom:updated>2017-03-09T00:44:31.158Z</atom:updated>
            <content:encoded><![CDATA[<p>At <a href="https://readytalk.com/">ReadyTalk</a> we’ve recently run into the issue of not having enough builders in our Jenkins instance. We were seeing backups in the build queue as large as 40+ jobs, but commonly we’d see around 20 builds waiting for a build machine. For the most part, those 20 or so jobs were in line to be run on 6 build machines, resulting in hours of backed up builds. Not ideal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F-N6mBj-86humYAtnzmAEA.jpeg" /><figcaption>Our old Jenkins build infrastructure</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*dlfSHFBTV46efSrRSxvDXg.png" /><figcaption>Common build queue</figcaption></figure><blockquote>…as an engineer on the ReadyTalk DevTools team it was my responsibility to get serious about our build infrastructure.</blockquote><p>Our dev teams were growing more and more impatient with the lack of build machines, and as an engineer on the ReadyTalk DevTools team it was my responsibility to get serious about our build infrastructure. When I started building new build infrastructure I knew I wanted everything to be in code. That’s where <a href="https://www.packer.io/">Packer</a> and <a href="https://www.ansible.com/">Ansible</a> come in.</p><p><strong>Packer</strong>. If you don’t already know, Packer is a tool made by <a href="https://www.hashicorp.com/">Hashicorp</a> for the purpose of provisioning operating system images. They support most, if not all, virtualization software and cloud providers. In my case, I’ll be using Packer to provision AMIs (Amazon Machine Images) in AWS. While Packer does have some provisioning modules (e.g. <a href="https://www.packer.io/docs/provisioners/shell.html">remote shell</a>), it’s not really meant to be the end all for provisioning an entire OS image. That’s where <strong>Ansible</strong> comes into play. I’m using Ansible to do all the heavy lifting once the base AMI is built. I’m using Ansible to copy files to my newly minted AMI, make new users, make directories, and install the needed OS packages (apt packages in my case). Packer has support for Ansible, along with other provisioners (Puppet, Chef, etc…), so it was sort of a no brainer for me to use it.</p><h3>Alright, let’s build the AMI.</h3><p>First I just wanted to get the AMI building out in EC2, so I started with a very basic Packer JSON file.</p><pre>{<br>  &quot;type&quot;: &quot;amazon-ebs&quot;,<br>  &quot;access_key&quot;: &quot;YOUR KEY HERE&quot;,<br>  &quot;secret_key&quot;: &quot;YOUR SECRET KEY HERE&quot;,<br>  &quot;region&quot;: &quot;us-east-1&quot;,<br>  &quot;source_ami&quot;: &quot;ami-116d857a&quot;,<br>  &quot;instance_type&quot;: &quot;t2.micro&quot;,<br>  &quot;ssh_username&quot;: &quot;admin&quot;,<br>  &quot;ami_name&quot;: &quot;basic_jenkins_builder_{{timestamp}}&quot;<br>}</pre><p>Once the file was built all I needed to do was run packer build ami.json and it started spinning up an EC2 instance in my region.</p><p>Now that I had a handle on how packer was actually working, it was time to really start building out my AMI with the addition of Ansible. If we want to use Ansible to provision our AMI we’re first going to need to install Ansible on our new AMI. Packer handles that for us using the shell provisioner :)</p><pre>&quot;provisioners&quot;: [  <br>  {<br>    &quot;type&quot;: &quot;shell&quot;,<br>    &quot;inline&quot;: [<br>      &quot;sudo apt-get install -y python-dev python-pip&quot;,<br>      &quot;sudo pip install ansible&quot;<br>    ]<br>  }<br>]</pre><p>Now that Ansible is installed, we can actually call it <a href="https://www.packer.io/docs/provisioners/ansible.html">as a provisioner</a> from the Packer code (this would also be in the provisioners section of the Packer file):</p><pre>{<br>  &quot;type&quot;: &quot;ansible&quot;,<br>  &quot;playbook_file&quot;: &quot;./playbook.yml&quot;<br>}</pre><p>Once we’ve called our Ansible provisioner, our possibilities are endless. Okay maybe not endless, but there are a ton of <a href="http://docs.ansible.com/ansible/list_of_all_modules.html">Ansible modules</a>.</p><h3>Now let’s hook up Jenkins to AWS and have it use our new AMI.</h3><p>First, we’ll need to install the <a href="https://wiki.jenkins-ci.org/display/JENKINS/Amazon+EC2+Plugin">AWS EC2 plugin</a> for Jenkins. Once that’s installed it’s time to configure the plugin (under the Manage Jenkins section of Jenkins). Find the drop down menu labeled Add a new cloud and select the Amazon EC2 option:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/155/1*a9BbPsqMwjD498XaxAd36A.png" /><figcaption>Add new EC2 builder</figcaption></figure><p>We should now see a new Amazon EC2 cloud entry in your main settings. From here it’s pretty self explanatory to get our AWS account hooked into Jenkins, but there are a few things we should do/pay attention to:</p><ul><li>Make sure we select the correct region for your AMI. AMI IDs are specific to regions. If we have the wrong region, Jenkins won’t be able to find the AMI.</li><li>Once we’ve added the main EC2 information, hit the “Test Connection” button to make sure we can talk to our AWS account. This will save us some debugging headache down the road. Trust me.</li><li>In the AMI section, make sure to hit the “Check AMI” button once we’ve added all the AMI information we see fit. This will make sure Jenkins can actually find the AMI in our given Region and Availability Zone.</li><li>Idle termination time: This will tell our new instance how long to stay up for before tearing itself down after a build. <a href="https://www.quora.com/When-you-use-an-AWS-EC2-instance-for-less-than-an-hour-are-you-charged-for-a-full-hour">I think EC2 instances are charged by the hour</a>, so 60 minutes seems like the best “bang for our buck” scenario.</li><li>Under the AMI section, there’s an advanced button. Most people won’t care about most of the settings there, but there’s one setting that’s kind of important. It called Instance Cap. This is how we can set a limit on how many EC2 instances we are willing to spin up at any given time. It’s probably best to put a limit on this so we don’t accidentally spin up 100 instances.</li></ul><p>Save all our settings, and let’s go test out our new builder. We don’t have to run a job against the new Jenkins AWS builder to test it. We can simply head to “Manage Jenkins -&gt; Manage Nodes” and we’ll see a new button in our node list that says “Provision via &lt;your ec2 instance name&gt;”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*r-EiLeIyH3czmGopq4mgxQ.png" /></figure><p>Click on that button and Jenkins will attempt to launch our new instance!</p><p>Now we can start assigning jobs to that instance via a label or just let any job run against it.</p><h3>What does this mean for our build infrastructure?</h3><ul><li>Now we’re no longer reliant on static hardware to run builds. Our build infrastructure is now dynamic. Yay!</li><li>The AWS EC2 plugin for Jenkins will “auto-scale”. Let’s say you’ve got one AWS EC2 instance spun up and waiting for a build in Jenkins. A build kicks off on that instance. Now another build gets registered in the Jenkins queue. If the one and only EC2 instance is busy, Jenkins will then spin up another for the build waiting in the queue. No more long waiting queues for builds.</li><li>Most importantly, all of your build infrastructure is now in code. No more hand managed systems. Packer and Ansible now control everything. This means tweaking or creating new AMIs is as simple as some code changes and a code review!</li></ul><h3>Question about how/why?</h3><p>Please feel free to reach out to me via <a href="https://twitter.com/DoctorNantucket">Twitter</a>. I kept this article at a high level on purpose, so if you’d like to get into details about exactly how I did something or why I chose this option over another solution, please contact me and I’d be happy to share :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e84f4d0a3853" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>