<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>All Posts - Filipe Felisbino</title><link>https://felisbino.dev/posts/</link><description>All Posts | Filipe Felisbino</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Sat, 10 Sep 2016 00:00:00 +0000</lastBuildDate><atom:link href="https://felisbino.dev/posts/" rel="self" type="application/rss+xml"/><item><title>Docker: Service discovery for docker containers on AWS</title><link>https://felisbino.dev/posts/docker-service-discovery-on-aws/</link><pubDate>Sat, 10 Sep 2016 00:00:00 +0000</pubDate><author>Filipe Felisbino</author><guid>https://felisbino.dev/posts/docker-service-discovery-on-aws/</guid><description>&lt;p>These days we see lots of fancy ways to do service discovery with docker. You see examples of people using
etcd, zookeeper, consul and so on. I recently had a project to migrate some solr clusters to docker and I
started looking at some of those tools and how they would fit that our current infrastructure.&lt;/p>
&lt;p>After some researching I found that the KISS way of doing service discovery on our environment was to use route53.
The main reasons for this decision were:&lt;/p></description></item><item><title>Ansible: Data structure handling and transformation</title><link>https://felisbino.dev/posts/ansible-data-structures/</link><pubDate>Fri, 02 Sep 2016 00:00:00 +0000</pubDate><author>Filipe Felisbino</author><guid>https://felisbino.dev/posts/ansible-data-structures/</guid><description><![CDATA[<p>From time to time I had some dificulties with handling data structures with ansible. Things like converting
a list of dicts to a list of values ( inside a dict ) or even filtering a list aren&rsquo;t always trivial.</p>
<p>Because of that, I&rsquo;ve written a small filter plugin called <code>json_query</code>, that allows you to do some cool
transformations with ansible. The filter uses jmespath ( <a href="http://jmespath.org/" target="_blank" rel="noopener noreffer ">http://jmespath.org/</a> ) a query language for
json data. The plugin is already merged to <code>devel</code> branch and will be released on 2.2 version of ansible.</p>]]></description></item><item><title>AWS custom-crafted load balancer with haproxy</title><link>https://felisbino.dev/posts/aws-load-balancer/</link><pubDate>Sat, 06 Aug 2016 00:00:00 +0000</pubDate><author>Filipe Felisbino</author><guid>https://felisbino.dev/posts/aws-load-balancer/</guid><description><![CDATA[<p>Today&rsquo;s tip is on how to launch a custom-crafted load balancer on AWS as a replacement for ELBs.</p>
<h2 id="motivation">Motivation</h2>
<p>First of all I need to say that I love AWS&rsquo; ELB. It is cost-effective and works just fine for most of the cases.</p>
<p>So why would I create a custom-crafted ELB? Well, there are some features that AWS&rsquo; ELB just don&rsquo;t support. Things like:</p>
<ul>
<li>A static IP or elastic IP entry point</li>
<li>UDP load balancing</li>
<li>Customized balancing strategy</li>
<li>Custom backend routing</li>
<li>One load balancer for multiple backends</li>
<li>SNI resolution(SSL routing)</li>
</ul>
<p>So if the ELB is not suited for your use case, do it yourself :-)</p>]]></description></item><item><title>Ansible: Using with_nested to merge a list with a dict</title><link>https://felisbino.dev/posts/ansible-nested-example/</link><pubDate>Wed, 20 Jan 2016 00:00:00 +0000</pubDate><author>Filipe Felisbino</author><guid>https://felisbino.dev/posts/ansible-nested-example/</guid><description><![CDATA[<p>I make heavy use of Ansible for AWS infrastructure provisioning. From creating VPCs, subnets, EC2 instances, security groups and so on.</p>
<p>Because we have a central point where we define per-environment networks, I recently got stuck with having to convert a list of subnets (just strings) to a list of dicts to be used by the <code>ec2_group</code> module. My list of subnets was something like:</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><pre tabindex="0"><code>internal_networks:
  - 10.100.32.0/20
  - 10.100.128.0/20
  - 10.100.144.0/20
  - 10.50.128.0/20
  - 10.50.144.0/20</code></pre></div>
<p>While the <code>ec2_group</code> expects its rules to be something like:</p>]]></description></item><item><title>Bash: Simple network ip/mask calculations with bash</title><link>https://felisbino.dev/posts/bash-calculating-ip-addresses/</link><pubDate>Sun, 06 Dec 2015 00:00:00 +0000</pubDate><author>Filipe Felisbino</author><guid>https://felisbino.dev/posts/bash-calculating-ip-addresses/</guid><description><![CDATA[<p>Here is quick-and-dirty network subnet calculator for bash:</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1">#converts an int to a netmask as 24 -&gt; 255.255.255.0</span>
</span></span><span class="line"><span class="cl">netmask<span class="o">()</span>
</span></span><span class="line"><span class="cl"><span class="o">{</span>
</span></span><span class="line"><span class="cl">    <span class="nb">local</span> <span class="nv">mask</span><span class="o">=</span><span class="k">$((</span><span class="m">0</span>xffffffff &lt;&lt; <span class="o">(</span><span class="m">32</span> <span class="o">-</span> <span class="nv">$1</span><span class="k">))</span><span class="o">)</span><span class="p">;</span> <span class="nb">shift</span>
</span></span><span class="line"><span class="cl">    <span class="nb">local</span> ip n
</span></span><span class="line"><span class="cl">    <span class="k">for</span> n in <span class="m">1</span> <span class="m">2</span> <span class="m">3</span> 4<span class="p">;</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">        <span class="nv">ip</span><span class="o">=</span><span class="k">$((</span>mask <span class="o">&amp;</span> <span class="m">0</span>xff<span class="k">))</span><span class="si">${</span><span class="nv">ip</span><span class="p">:+.</span><span class="si">}</span><span class="nv">$ip</span>
</span></span><span class="line"><span class="cl">        <span class="nv">mask</span><span class="o">=</span><span class="k">$((</span>mask &gt;&gt; <span class="m">8</span><span class="k">))</span>
</span></span><span class="line"><span class="cl">    <span class="k">done</span>
</span></span><span class="line"><span class="cl">    <span class="nb">echo</span> <span class="nv">$ip</span>
</span></span><span class="line"><span class="cl"><span class="o">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">#receives a ip/mask parameter and returns the nth ip in that range:</span>
</span></span><span class="line"><span class="cl">get_nth_ip<span class="o">()</span>
</span></span><span class="line"><span class="cl"><span class="o">{</span>
</span></span><span class="line"><span class="cl">    <span class="nv">IFS</span><span class="o">=</span><span class="s2">&#34;. /&#34;</span> <span class="nb">read</span> -r i1 i2 i3 i4 mask <span class="o">&lt;&lt;&lt;</span> <span class="nv">$1</span>
</span></span><span class="line"><span class="cl">    <span class="nv">IFS</span><span class="o">=</span><span class="s2">&#34; .&#34;</span> <span class="nb">read</span> -r m1 m2 m3 m4 <span class="o">&lt;&lt;&lt;</span> <span class="k">$(</span>netmask <span class="nv">$mask</span><span class="k">)</span>
</span></span><span class="line"><span class="cl">    <span class="nb">printf</span> <span class="s2">&#34;%d.%d.%d.%d\n&#34;</span> <span class="s2">&#34;</span><span class="k">$((</span>i1 <span class="o">&amp;</span> m1<span class="k">))</span><span class="s2">&#34;</span> <span class="s2">&#34;</span><span class="k">$((</span>i2 <span class="o">&amp;</span> m2<span class="k">))</span><span class="s2">&#34;</span> <span class="s2">&#34;</span><span class="k">$((</span>i3 <span class="o">&amp;</span> m3<span class="k">))</span><span class="s2">&#34;</span> <span class="s2">&#34;</span><span class="k">$((</span><span class="nv">$2</span> <span class="o">+</span> <span class="o">(</span>i4 <span class="o">&amp;</span> m4<span class="k">))</span><span class="s2">)&#34;</span>
</span></span><span class="line"><span class="cl"><span class="o">}</span></span></span></code></pre></div></div>
<p>To find the 10th ip in a subnet you just need to:</p>]]></description></item><item><title>Ansible: Flattening a list of dicts to a single dict</title><link>https://felisbino.dev/posts/ansible-flattening-list-of-dicts/</link><pubDate>Thu, 03 Dec 2015 00:00:00 +0000</pubDate><author>Filipe Felisbino</author><guid>https://felisbino.dev/posts/ansible-flattening-list-of-dicts/</guid><description><![CDATA[<p>Ansible is a great tool for automation. It has lots of modules that makes our lives easier. As a heavy-user of ansible for infrastructure provisioning on AWS, I sometimes get frustrated to have to deal with different data structures used by modules.</p>
<p>One example I had to deal with recently was the tags attribute of ec2_asg and ec2_tag. You cannot just pass the same value for both of them because ec2_asg tags attribute expects a list of dicts, while ec2_tag expects just a dict. That difference is because ec2_asg&rsquo;s dicts have an optional attribute called <em>propagate_at_launch</em>.</p>]]></description></item></channel></rss>