<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Arrfab's blog - ansible</title><link href="https://arrfab.net/" rel="alternate"></link><link href="https://arrfab.net/feeds/ansible.atom.xml" rel="self"></link><id>https://arrfab.net/</id><updated>2020-10-28T00:00:00+01:00</updated><subtitle>Some tips and tricks, mostly around CentOS</subtitle><entry><title>Using connection delegation with mitogen for Ansible</title><link href="https://arrfab.net/posts/2020/Oct/28/using-connection-delegation-with-mitogen-for-ansible/" rel="alternate"></link><published>2020-10-28T00:00:00+01:00</published><updated>2020-10-28T00:00:00+01:00</updated><author><name>Fabian Arrotin</name></author><id>tag:arrfab.net,2020-10-28:/posts/2020/Oct/28/using-connection-delegation-with-mitogen-for-ansible/</id><summary type="html">&lt;p&gt;This should be a very short blog post, but long enough to justify a blog post instead of a 'tweet' : I had myself a small issue with mitogen plugin in our Ansible infra.&lt;/p&gt;
&lt;p&gt;To cut a long story short, everybody knows that ansible relies on ssh as transport. So one can use traditional  ~/.ssh/config tuning to declare ProxyJump for some hosts, etc&lt;/p&gt;
&lt;p&gt;But when you use mitogen (we do), in the &lt;a href="https://mitogen.networkgenomics.com/ansible_detailed.html#connection-delegation"&gt;official doc&lt;/a&gt; there is a mention of specific parameter for connection delegation : &lt;code&gt;mitogen_via&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The simple example on the webpage seems trivial and if you have multiple hosts that need to be configured from remote ansible+mitogen combo, using mitogen would speed things up as it would &lt;em&gt;know&lt;/em&gt; about the host topology.&lt;/p&gt;
&lt;p&gt;That's what I thought when having a look at the simple inventory on that web page: &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;[dc2]&lt;/span&gt;
&lt;span class="na"&gt;web1.dc2&lt;/span&gt;
&lt;span class="na"&gt;web2.dc2&lt;/span&gt;
&lt;span class="na"&gt;web3.dc2&lt;/span&gt;

&lt;span class="k"&gt;[dc2:vars]&lt;/span&gt;
&lt;span class="na"&gt;mitogen_via&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;bastion.dc2&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Sounds easy but when I tried quickly to use mitogen_via , something that I thought would be obvious in fact wasn't.
My understanding was that mitogen would automatically force agent forwarding when going through the bastion host.
A simple &lt;code&gt;ansible -m ping&lt;/code&gt;  (let's assume web1.dc2 in their example) returned …&lt;/p&gt;</summary><content type="html">&lt;p&gt;This should be a very short blog post, but long enough to justify a blog post instead of a 'tweet' : I had myself a small issue with mitogen plugin in our Ansible infra.&lt;/p&gt;
&lt;p&gt;To cut a long story short, everybody knows that ansible relies on ssh as transport. So one can use traditional  ~/.ssh/config tuning to declare ProxyJump for some hosts, etc&lt;/p&gt;
&lt;p&gt;But when you use mitogen (we do), in the &lt;a href="https://mitogen.networkgenomics.com/ansible_detailed.html#connection-delegation"&gt;official doc&lt;/a&gt; there is a mention of specific parameter for connection delegation : &lt;code&gt;mitogen_via&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The simple example on the webpage seems trivial and if you have multiple hosts that need to be configured from remote ansible+mitogen combo, using mitogen would speed things up as it would &lt;em&gt;know&lt;/em&gt; about the host topology.&lt;/p&gt;
&lt;p&gt;That's what I thought when having a look at the simple inventory on that web page: &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;[dc2]&lt;/span&gt;
&lt;span class="na"&gt;web1.dc2&lt;/span&gt;
&lt;span class="na"&gt;web2.dc2&lt;/span&gt;
&lt;span class="na"&gt;web3.dc2&lt;/span&gt;

&lt;span class="k"&gt;[dc2:vars]&lt;/span&gt;
&lt;span class="na"&gt;mitogen_via&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;bastion.dc2&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Sounds easy but when I tried quickly to use mitogen_via , something that I thought would be obvious in fact wasn't.
My understanding was that mitogen would automatically force agent forwarding when going through the bastion host.
A simple &lt;code&gt;ansible -m ping&lt;/code&gt;  (let's assume web1.dc2 in their example) returned me :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;web1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dc2&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;UNREACHABLE&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
    &lt;span class="ss"&gt;&amp;quot;changed&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;&amp;quot;msg&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;error occurred on host bastion.dc2: SSH authentication is incorrect&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;&amp;quot;unreachable&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Well, we can see from the returned json that it was trying to pass through bastion.dc2 and that's confirmed on web1.dc2 : &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;Oct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;52&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;36&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;web1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dc2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sshd&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;12913&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;Connection&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;closed&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;by&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ip_from_bastion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dc2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;56728&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;preauth&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then I thought about something that was obvious to me but that mitogen (just reusing underlying ssh) doesn't do automatically : Forwarding the ssh agent to the nodes behind.&lt;/p&gt;
&lt;p&gt;We can easily solve that with one simple ansible parameter : ansible has the &lt;code&gt;ansible_ssh_common_args&lt;/code&gt; and &lt;code&gt;ansible_ssh_extra_args&lt;/code&gt; parameters, specific to the &lt;a href="https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#connecting-to-hosts-behavioral-inventory-parameters"&gt;SSH connection&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So what about we force Agent Forward just on that bastion host and see how that works ? 
That means that in our inventory (but can go to host_vars/bastion.dc2 too) we just have to add parameter:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;bastion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dc2&lt;/span&gt; &lt;span class="n"&gt;ansible_ssh_extra_args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;-o ForwardAgent=yes&amp;#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Let's try again :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;web1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dc2&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;SUCCESS&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
    &lt;span class="ss"&gt;&amp;quot;ansible_facts&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
        &lt;span class="ss"&gt;&amp;quot;discovered_interpreter_python&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;/usr/bin/python&amp;quot;&lt;/span&gt;
    &lt;span class="err"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;&amp;quot;changed&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;&amp;quot;ping&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;pong&amp;quot;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Good, so we can push that for our bastion hosts (used in inventory for mitogen_via) in host_vars or group_vars and call it a day.
The reason why I prefer using &lt;code&gt;ansible_ssh_extra_args&lt;/code&gt; is that it will merge and add settings, in case you have already something like this in your ansible.cfg : &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;[ssh_connection]&lt;/span&gt;
&lt;span class="na"&gt;ssh_args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;I like the logic that we don't need to modify ~/.ssh/config with all exceptions to reflect the infra layout but we can just reflect it in ansible inventory&lt;/p&gt;</content><category term="CentOS"></category><category term="ansible"></category></entry><entry><title>Implementing Zabbix custom LLD rules with Ansible</title><link href="https://arrfab.net/posts/2018/Nov/07/implementing-zabbix-custom-lld-rules-with-ansible/" rel="alternate"></link><published>2018-11-07T00:00:00+01:00</published><updated>2018-11-07T00:00:00+01:00</updated><author><name>Fabian Arrotin</name></author><id>tag:arrfab.net,2018-11-07:/posts/2018/Nov/07/implementing-zabbix-custom-lld-rules-with-ansible/</id><summary type="html">&lt;p&gt;While I have to admit that I'm using &lt;a href="http://www.zabbix.com"&gt;Zabbix&lt;/a&gt; since the 1.8.x era, I also have to admit that I'm not an expert, and that one can learn new things every day. I recently had to implement a new template for a custom service, that is multi-instances aware, and so can be started multiple times with various configurations, and so with its own set of settings, like tcp port on which to listen, etc .. , but also the number of instances running as it can be different from one node to the next one.&lt;/p&gt;
&lt;p&gt;I was thinking about the best way to implement this through Zabbix, and my initial idea was to just have one template per possible instance type, that would though use &lt;a href="https://www.zabbix.com/documentation/3.2/manual/config/macros"&gt;macros&lt;/a&gt; defined at the host level, to know which port to check, etc .. so in fact backporting into zabbix what configuration management (Ansible in our case) already has to know to deploy such app instance.&lt;/p&gt;
&lt;p&gt;But parallel to that, I always liked the fact that Zabbix itself has some internal tools to auto-discover items and so triggers for those : That's called &lt;a href="https://www.zabbix.com/documentation/3.0/manual/discovery/low_level_discovery"&gt;Low-level Discovery&lt;/a&gt; (LLD in short). &lt;/p&gt;
&lt;p&gt;By default, if you use (or have modified) some …&lt;/p&gt;</summary><content type="html">&lt;p&gt;While I have to admit that I'm using &lt;a href="http://www.zabbix.com"&gt;Zabbix&lt;/a&gt; since the 1.8.x era, I also have to admit that I'm not an expert, and that one can learn new things every day. I recently had to implement a new template for a custom service, that is multi-instances aware, and so can be started multiple times with various configurations, and so with its own set of settings, like tcp port on which to listen, etc .. , but also the number of instances running as it can be different from one node to the next one.&lt;/p&gt;
&lt;p&gt;I was thinking about the best way to implement this through Zabbix, and my initial idea was to just have one template per possible instance type, that would though use &lt;a href="https://www.zabbix.com/documentation/3.2/manual/config/macros"&gt;macros&lt;/a&gt; defined at the host level, to know which port to check, etc .. so in fact backporting into zabbix what configuration management (Ansible in our case) already has to know to deploy such app instance.&lt;/p&gt;
&lt;p&gt;But parallel to that, I always liked the fact that Zabbix itself has some internal tools to auto-discover items and so triggers for those : That's called &lt;a href="https://www.zabbix.com/documentation/3.0/manual/discovery/low_level_discovery"&gt;Low-level Discovery&lt;/a&gt; (LLD in short). &lt;/p&gt;
&lt;p&gt;By default, if you use (or have modified) some zabbix templates, you can see those in actions for the mounted filesystems or even the present network interfaces in your linux OS. That's the "magic" : you added a new mount point or a new interface ? Zabbix discovers it automatically and start monitoring it, and also graph values for those.&lt;/p&gt;
&lt;p&gt;So back to our monitoring problem and the need for multiple templates : what if we could use LLD too and so have Zabbix automatically checking our deployed instances (multiple ones) automatically ? The good is that we can : one can create &lt;a href="https://www.zabbix.com/documentation/3.0/manual/discovery/low_level_discovery#creating_custom_lld_rules"&gt;custom LLD rules&lt;/a&gt; and so it would work OOTB when only one template would be added for those nodes.&lt;/p&gt;
&lt;p&gt;If you read the link above for custom LLD rule, you'll see some examples about a script being called at the agent level, from the zabbix server, at periodic interval, to "discover" those custom discovery checks.
The interesting part to notice is that it's a json that is returned to zabbix server , pointing to a new key, that is declared at the template level.&lt;/p&gt;
&lt;p&gt;So it (usually) goes like this : &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;create a template&lt;/li&gt;
&lt;li&gt;create a new discovery rule, give it a name and a key (and also eventually add Filters)&lt;/li&gt;
&lt;li&gt;deploy a new &lt;a href="https://www.zabbix.com/documentation/3.0/manual/config/items/userparameters"&gt;UserParameter&lt;/a&gt; at the agent level reporting to that key the json string it needs to declare to zabbix server&lt;/li&gt;
&lt;li&gt;Zabbix server receives/parses that json and based on the checks/variables declared in that json, it will create , based on those returned macros, some Item Prototypes, Trigger prototypes and so on ...&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Magic! ... except that in my specific case, for some reasons I never allowed the zabbix user to really launch commands, due to limited rights and also the Selinux context in which it's running (for interested people, it's running in the &lt;a href="https://arrfab.net/posts/2016/Nov/25/zabbix-selinux-and-centos-731611/"&gt;zabbix_agent_t&lt;/a&gt; context)&lt;/p&gt;
&lt;p&gt;I suddenly didn't want to change that base rule for our deployments, but the good news is that you don't have to use UserParameter for LLD ! . It's true that if you look at the existing Discovery Rules for "Network interface discovery", you'll see the key net.if.discovery, that is used for everything after, but the Type is "Zabbix agent". We can use something else in that list, like we already do for a "normal" check&lt;/p&gt;
&lt;p&gt;I'm already (ab)using the &lt;a href="https://www.zabbix.com/documentation/3.0/manual/config/items/itemtypes/trapper"&gt;Trapper item type&lt;/a&gt; for a lot of hardware checks : reason is simple : as zabbix user is limited (and I don't want to grant more rights for it), I have some scripts checking for hardware raid controllers (if any), etc, and reporting back to zabbix through zabbix_sender.&lt;/p&gt;
&lt;p&gt;Let's use the same logic for the json string to be returned to Zabbix server for LLD. (as yes, Trapper is in the list for the discovery rule Type.&lt;/p&gt;
&lt;p&gt;It's even easier for us, as we'll control that through &lt;a href="http:///www.ansible.com"&gt;Ansible&lt;/a&gt; : It's what is already used to deploy/configure our &lt;a href="https://repospanner.org"&gt;RepoSpanner&lt;/a&gt; instances so we have all the logic there.&lt;/p&gt;
&lt;p&gt;Let's first start by creating the new template for repospanner, and create a discovery rule (detecting each instances and settings) :&lt;/p&gt;
&lt;p&gt;&lt;img alt="zabbix-discovery-type.png" src="/images/zabbix-discovery-type.png"&gt;&lt;/p&gt;
&lt;p&gt;You can then apply that template to host[s] and wait ... but first we need to report back from agent to server which instances are deployed/running. So let's see how to implement that through ansible.&lt;/p&gt;
&lt;p&gt;To keep it short, in Ansible we have the following (default values, not the correct ones) variables (from roles/repospanner/default.yml):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;...
&lt;span class="nv"&gt;repospanner_instances&lt;/span&gt;:
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;: &lt;span class="nv"&gt;default&lt;/span&gt;
    &lt;span class="nv"&gt;admin_cli&lt;/span&gt;: &lt;span class="nv"&gt;False&lt;/span&gt;
    &lt;span class="nv"&gt;admin_ca_cert&lt;/span&gt;:
    &lt;span class="nv"&gt;admin_cert&lt;/span&gt;:
    &lt;span class="nv"&gt;admin_key&lt;/span&gt;:
    &lt;span class="nv"&gt;rpc_port&lt;/span&gt;: &lt;span class="mi"&gt;8443&lt;/span&gt;
    &lt;span class="nv"&gt;rpc_allow_from&lt;/span&gt;:
      &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;127&lt;/span&gt;.&lt;span class="mi"&gt;0&lt;/span&gt;.&lt;span class="mi"&gt;0&lt;/span&gt;.&lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="nv"&gt;http_port&lt;/span&gt;: &lt;span class="mi"&gt;8444&lt;/span&gt;
    &lt;span class="nv"&gt;http_allow_from&lt;/span&gt;:
      &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;127&lt;/span&gt;.&lt;span class="mi"&gt;0&lt;/span&gt;.&lt;span class="mi"&gt;0&lt;/span&gt;.&lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="nv"&gt;tls_ca_cert&lt;/span&gt;: &lt;span class="nv"&gt;ca&lt;/span&gt;.&lt;span class="nv"&gt;crt&lt;/span&gt;
    &lt;span class="nv"&gt;tls_cert&lt;/span&gt;: &lt;span class="nv"&gt;nodea&lt;/span&gt;.&lt;span class="nv"&gt;regiona&lt;/span&gt;.&lt;span class="nv"&gt;crt&lt;/span&gt;
    &lt;span class="nv"&gt;tls_key&lt;/span&gt;: &lt;span class="nv"&gt;nodea&lt;/span&gt;.&lt;span class="nv"&gt;regiona&lt;/span&gt;.&lt;span class="nv"&gt;key&lt;/span&gt;
    &lt;span class="nv"&gt;my_cn&lt;/span&gt;: &lt;span class="nv"&gt;localhost&lt;/span&gt;.&lt;span class="nv"&gt;localdomain&lt;/span&gt;
    &lt;span class="nv"&gt;master_node&lt;/span&gt; : &lt;span class="nv"&gt;nodea&lt;/span&gt;.&lt;span class="nv"&gt;regiona&lt;/span&gt;.&lt;span class="nv"&gt;domain&lt;/span&gt;.&lt;span class="nv"&gt;com&lt;/span&gt; # &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;know&lt;/span&gt; &lt;span class="nv"&gt;how&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;join&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;cluster&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;other&lt;/span&gt; &lt;span class="nv"&gt;nodes&lt;/span&gt;
    &lt;span class="nv"&gt;init_node&lt;/span&gt;: &lt;span class="nv"&gt;True&lt;/span&gt; # &lt;span class="nv"&gt;To&lt;/span&gt; &lt;span class="nv"&gt;be&lt;/span&gt; &lt;span class="nv"&gt;declared&lt;/span&gt; &lt;span class="nv"&gt;only&lt;/span&gt; &lt;span class="nv"&gt;on&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;first&lt;/span&gt; &lt;span class="nv"&gt;node&lt;/span&gt;
...
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;That simple example has only one instance, but you can easily see how to have multiple ones, etc
So here is the logic : let's have ansible, when configuring the node, create the file that will be used zabbix_sender (triggered by ansible itself) to send the json to zabbix server. zabbix_sender can use a file that is separated (man page) like this :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;hostname (or '-' to use name configured in zabbix_agentd.conf) &lt;/li&gt;
&lt;li&gt;key &lt;/li&gt;
&lt;li&gt;value&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Those three fields &lt;em&gt;have&lt;/em&gt; to be separated by one space only, and important : you can't have extra empty line (but something can you easily see when playing with this the first time)&lt;/p&gt;
&lt;p&gt;How does our file (roles/repospanner/templates/zabbix-repospanner-lld.j2) look like ? : &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;repospanner&lt;/span&gt;.&lt;span class="nv"&gt;lld&lt;/span&gt;.&lt;span class="nv"&gt;instances&lt;/span&gt; { &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;: [ {&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;instance&lt;/span&gt; &lt;span class="nv"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;repospanner_instances&lt;/span&gt; &lt;span class="o"&gt;-%&lt;/span&gt;} { &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="s"&gt;{{ &amp;#39;{#INSTANCE}&amp;#39; }}&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;: &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="s"&gt;{{ instance.name }}&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;, &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="s"&gt;{{ &amp;#39;{#RPCPORT}&amp;#39; }}&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;: &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="s"&gt;{{ instance.rpc_port }}&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;, &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="s"&gt;{{ &amp;#39;{#HTTPPORT}&amp;#39; }}&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;: &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="s"&gt;{{ instance.http_port }}&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt; } {&lt;span class="o"&gt;%-&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;not&lt;/span&gt; &lt;span class="k"&gt;loop&lt;/span&gt;.&lt;span class="nv"&gt;last&lt;/span&gt; &lt;span class="o"&gt;-%&lt;/span&gt;},{&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;endif&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;} {&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nv"&gt;endfor&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;} ] }
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;If you have already used jinja2 templates for Ansible, it's quite easy to understand. But I have to admit that I had troubles with the {#INSTANCE} one : that one isn't an ansible variable, but rather a fixed name for the macro that we'll send to zabbix (and so reused as macro everywhere). But ansible, when trying to translate the jinja2 template, was complaining about missing "comment' : Indeed {# ... #} is a &lt;a href="http://jinja.pocoo.org/docs/dev/templates/#comments"&gt;comment in jinja2&lt;/a&gt;. So the best way (thanks to people in #ansible for that trick) is to include it in {{ }} brackets but then escape it so that it would be rendered as {#INSTANCE} (nice to know if you have to do that too ....)&lt;/p&gt;
&lt;p&gt;The rest is trival : excerpt from monitoring.yml (included in that repospanner role) : &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="x"&gt;- name: Distributing zabbix repospanner check file&lt;/span&gt;
&lt;span class="x"&gt;  template:&lt;/span&gt;
&lt;span class="x"&gt;    src: &amp;quot;&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;item&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt;.j2&amp;quot;&lt;/span&gt;
&lt;span class="x"&gt;    dest: &amp;quot;/usr/lib/zabbix/&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;item&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt;&amp;quot;&lt;/span&gt;
&lt;span class="x"&gt;    mode: 0755&lt;/span&gt;
&lt;span class="x"&gt;  with_items:&lt;/span&gt;
&lt;span class="x"&gt;    - zabbix-repospanner-check&lt;/span&gt;
&lt;span class="x"&gt;    - zabbix-repospanner-lld&lt;/span&gt;
&lt;span class="x"&gt;  register: zabbix_templates   &lt;/span&gt;
&lt;span class="x"&gt;  tags:&lt;/span&gt;
&lt;span class="x"&gt;    - templates&lt;/span&gt;

&lt;span class="x"&gt;- name: Launching LLD to announce to zabbix&lt;/span&gt;
&lt;span class="x"&gt;  shell: /bin/zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -i /usr/lib/zabbix/zabbix-repospanner-lld&lt;/span&gt;
&lt;span class="x"&gt;  when: zabbix_templates is changed&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;And this is how is rendered on one of my test node : &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;repospanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lld&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;instances&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;data&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;{#INSTANCE}&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;namespace_rpms&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;{#RPCPORT}&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;8443&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;{#HTTPPORT}&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;8444&amp;quot;&lt;/span&gt; &lt;span class="err"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;{#INSTANCE}&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;namespace_centos&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;{#RPCPORT}&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;8445&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;{#HTTPPORT}&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="ss"&gt;&amp;quot;8446&amp;quot;&lt;/span&gt; &lt;span class="err"&gt;}&lt;/span&gt;  &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="err"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;As ansible auto-announces/push that back to zabbix, zabbix server can automatically start creating (through LLD, based on the item prototypes) some checks and triggers/graphs and so start monitoring each newly instance.
You want to add a third one ? (we have two in our case) : ansible pushes the config, would modify the .j2 template and would notify zabbix server. etc, etc ...&lt;/p&gt;
&lt;p&gt;The rest is just "normal" operation for zabbix : you can create items/trigger prototypes and just use those special Macros coming from LLD : &lt;/p&gt;
&lt;p&gt;&lt;img alt="zabbix-item-prototypes.png" src="/images/zabbix-item-prototypes.png"&gt;&lt;/p&gt;
&lt;p&gt;It was worth spending some time in the LLD doc and in #zabbix to discuss LLD, but once you see the added value, and that you can automatically configure it through Ansible, one can see how powerful it can be.&lt;/p&gt;</content><category term="CentOS"></category><category term="sysadmin"></category><category term="Ansible"></category><category term="Zabbix"></category></entry><entry><title>Using Ansible Openstack modules on CentOS 7</title><link href="https://arrfab.net/posts/2017/Oct/11/using-ansible-openstack-modules-on-centos-7/" rel="alternate"></link><published>2017-10-11T00:00:00+02:00</published><updated>2017-10-11T00:00:00+02:00</updated><author><name>Fabian Arrotin</name></author><id>tag:arrfab.net,2017-10-11:/posts/2017/Oct/11/using-ansible-openstack-modules-on-centos-7/</id><summary type="html">&lt;p&gt;Suppose that you have a RDO/Openstack cloud already in place, but that you'd want to automate some operations : what can you do ? On my side, I already &lt;a href="/posts/2017/May/08/deploying-openstack-through-puppet-on-centos-7-a-journey/"&gt;mentioned&lt;/a&gt; that I used puppet to deploy initial clouds, but I still prefer Ansible myself when having to launch ad-hoc tasks, or even change configuration[s]. It's particulary true for our &lt;a href="https://ci.centos.org"&gt;CI environment&lt;/a&gt; where we run "agentless" so all configuration changes happen through Ansible.&lt;/p&gt;
&lt;p&gt;The good news is that Ansible has already some modules for &lt;a href="http://docs.ansible.com/ansible/latest/list_of_cloud_modules.html#openstack"&gt;Openstack&lt;/a&gt; but it has some requirements and a little bit of understanding before being able to use those.&lt;/p&gt;
&lt;p&gt;First of all, all the ansible os_ modules need &lt;a href="https://pypi.python.org/pypi/shade"&gt;"shade"&lt;/a&gt; on the host included in the play, and that will be responsible of all os_ modules launch. 
At the time of writing this post, it's &lt;em&gt;not&lt;/em&gt; yet available on mirror.centos.org, (a review is open so that will be soon available directly) but you can find the pkg on &lt;a href="https://cbs.centos.org/koji/buildinfo?buildID=20086"&gt;our CBS builders&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Once installed, a simple os_image task was directly failing, despite the fact that auth: was present, and that's due to a simple reason : Ansible os_ modules still want to use v2 API, while it's now defaulting …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Suppose that you have a RDO/Openstack cloud already in place, but that you'd want to automate some operations : what can you do ? On my side, I already &lt;a href="/posts/2017/May/08/deploying-openstack-through-puppet-on-centos-7-a-journey/"&gt;mentioned&lt;/a&gt; that I used puppet to deploy initial clouds, but I still prefer Ansible myself when having to launch ad-hoc tasks, or even change configuration[s]. It's particulary true for our &lt;a href="https://ci.centos.org"&gt;CI environment&lt;/a&gt; where we run "agentless" so all configuration changes happen through Ansible.&lt;/p&gt;
&lt;p&gt;The good news is that Ansible has already some modules for &lt;a href="http://docs.ansible.com/ansible/latest/list_of_cloud_modules.html#openstack"&gt;Openstack&lt;/a&gt; but it has some requirements and a little bit of understanding before being able to use those.&lt;/p&gt;
&lt;p&gt;First of all, all the ansible os_ modules need &lt;a href="https://pypi.python.org/pypi/shade"&gt;"shade"&lt;/a&gt; on the host included in the play, and that will be responsible of all os_ modules launch. 
At the time of writing this post, it's &lt;em&gt;not&lt;/em&gt; yet available on mirror.centos.org, (a review is open so that will be soon available directly) but you can find the pkg on &lt;a href="https://cbs.centos.org/koji/buildinfo?buildID=20086"&gt;our CBS builders&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Once installed, a simple os_image task was directly failing, despite the fact that auth: was present, and that's due to a simple reason : Ansible os_ modules still want to use v2 API, while it's now defaulting to v3 in Pike release. There is no way to force ansible itself to use v3, but as it uses shade behind the scene, there is a way to force this through &lt;a href="https://docs.openstack.org/os-client-config/latest/index.html"&gt;os-client-config&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;That means that you just have to use a .yaml file (does that sound familiar for ansible ?) that will contain everything you  need to know about specific cloud, and then just in ansible declare which cloud you're configuring.&lt;/p&gt;
&lt;p&gt;That clouds.yaml file can be under $current_directory, ~/.config/openstack or /etc/openstack so it's up to you to decide where you want to temporary host it, but I selected /etc/openstack/ :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;: &lt;span class="nv"&gt;Ensuring&lt;/span&gt; &lt;span class="nv"&gt;we&lt;/span&gt; &lt;span class="nv"&gt;have&lt;/span&gt; &lt;span class="nv"&gt;required&lt;/span&gt; &lt;span class="nv"&gt;pkgs&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;ansible&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;openstack&lt;/span&gt;
  &lt;span class="nv"&gt;yum&lt;/span&gt;:
    &lt;span class="nv"&gt;name&lt;/span&gt;: &lt;span class="nv"&gt;python2&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;shade&lt;/span&gt;
    &lt;span class="nv"&gt;state&lt;/span&gt;: &lt;span class="nv"&gt;installed&lt;/span&gt;

&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;: &lt;span class="nv"&gt;Ensuring&lt;/span&gt; &lt;span class="nv"&gt;local&lt;/span&gt; &lt;span class="nv"&gt;directory&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;hold&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;os&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;client&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;config&lt;/span&gt; &lt;span class="nv"&gt;file&lt;/span&gt;
  &lt;span class="nv"&gt;file&lt;/span&gt;:
    &lt;span class="nv"&gt;path&lt;/span&gt;: &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;openstack&lt;/span&gt;
    &lt;span class="nv"&gt;state&lt;/span&gt;: &lt;span class="nv"&gt;directory&lt;/span&gt;
    &lt;span class="nv"&gt;owner&lt;/span&gt;: &lt;span class="nv"&gt;root&lt;/span&gt;
    &lt;span class="nv"&gt;group&lt;/span&gt;: &lt;span class="nv"&gt;root&lt;/span&gt;

&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;: &lt;span class="nv"&gt;Adding&lt;/span&gt; &lt;span class="nv"&gt;clouds&lt;/span&gt;.&lt;span class="nv"&gt;yaml&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;os&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;client&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;config&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;further&lt;/span&gt; &lt;span class="nv"&gt;actions&lt;/span&gt;
  &lt;span class="nv"&gt;template&lt;/span&gt;:
    &lt;span class="nv"&gt;src&lt;/span&gt;: &lt;span class="nv"&gt;clouds&lt;/span&gt;.&lt;span class="nv"&gt;yaml&lt;/span&gt;.&lt;span class="nv"&gt;j2&lt;/span&gt;
    &lt;span class="nv"&gt;dest&lt;/span&gt;: &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;openstack&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;clouds&lt;/span&gt;.&lt;span class="nv"&gt;yaml&lt;/span&gt;
    &lt;span class="nv"&gt;owner&lt;/span&gt;: &lt;span class="nv"&gt;root&lt;/span&gt;
    &lt;span class="nv"&gt;group&lt;/span&gt;: &lt;span class="nv"&gt;root&lt;/span&gt;
    &lt;span class="nv"&gt;mode&lt;/span&gt;: &lt;span class="mi"&gt;0700&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Of course such clouds.yaml file is itself a jinja2 template distributed by ansible on the host in the play &lt;em&gt;before&lt;/em&gt; using the os_* modules : &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="x"&gt;clouds:&lt;/span&gt;
&lt;span class="x"&gt;  &lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;cloud_name&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt;:&lt;/span&gt;
&lt;span class="x"&gt;    auth:&lt;/span&gt;
&lt;span class="x"&gt;      username: admin&lt;/span&gt;
&lt;span class="x"&gt;      project_name: admin&lt;/span&gt;
&lt;span class="x"&gt;      password: &lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;openstack_admin_pass&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;span class="x"&gt;      auth_url: http://&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;openstack_controller&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt;:5000/v3/&lt;/span&gt;
&lt;span class="x"&gt;      user_domain_name: default&lt;/span&gt;
&lt;span class="x"&gt;      project_domain_name: default&lt;/span&gt;
&lt;span class="x"&gt;    identity_api_version: 3&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You just have to adapt to your needs (see &lt;a href="https://docs.openstack.org/os-client-config/latest/user/configuration.html"&gt;doc&lt;/a&gt; for this) but the interesting part is the identity_api_version to force v3.&lt;/p&gt;
&lt;p&gt;Then, you can use all that in a simple way through ansible tasks, in this case adding users to a project :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Configuring&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;OpenStack&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;user&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;os_user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;cloud&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;&amp;quot;{{ cloud_name }}&amp;quot;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;default_project&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;&amp;quot;{{ item.0.name }}&amp;quot;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;domain&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;&amp;quot;{{ item.0.domain_id }}&amp;quot;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;&amp;quot;{{ item.1.login }}&amp;quot;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;&amp;quot;{{ item.1.email }}&amp;quot;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;&amp;quot;{{ item.1.password }}&amp;quot;&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;with_subelements&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;&amp;quot;{{ cloud_projects }}&amp;quot;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;no_log&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;True&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;From a variables point of view, I decided to just have a simple structure to host project/users/roles/quotas like this : &lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nl"&gt;cloud_projects&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;domain_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;quota_cores&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;quota_instances&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;quota_ram&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;40960&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nl"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;login&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;demo_user&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nl"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="nv"&gt;@centos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;org&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nl"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Ch&lt;/span&gt;&lt;span class="nv"&gt;@ngeM3&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;role&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;admin&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;can&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;be&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_member_&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ow"&gt;or&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;admin&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;login&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;demo_user2&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nl"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;demo2&lt;/span&gt;&lt;span class="nv"&gt;@centos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;org&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nl"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Ch&lt;/span&gt;&lt;span class="nv"&gt;@ngeMe2&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now that it works, you can explore all the other os_* modules and I'm already using those to :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Import cloud images in glance&lt;/li&gt;
&lt;li&gt;Create networks and subnets in neutron&lt;/li&gt;
&lt;li&gt;Create projects/users/roles in keystone&lt;/li&gt;
&lt;li&gt;Change quotas for those projects&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I'm just discovering how powerful those tools are, so I'll probably discover much more interesting things to do with those later. &lt;/p&gt;</content><category term="CentOS"></category><category term="sysadmin"></category><category term="infra"></category><category term="RDO"></category><category term="Openstack"></category><category term="ansible"></category></entry><entry><title>Provisioning quickly nodes in a SeaMicro chassis with Ansible</title><link href="https://arrfab.net/posts/2015/Jan/12/provisioning-quickly-nodes-in-a-seamicro-chassis-with-ansible/" rel="alternate"></link><published>2015-01-12T15:19:00+01:00</published><updated>2015-01-12T15:19:00+01:00</updated><author><name>Fabian Arrotin</name></author><id>tag:arrfab.net,2015-01-12:/posts/2015/Jan/12/provisioning-quickly-nodes-in-a-seamicro-chassis-with-ansible/</id><summary type="html">&lt;p&gt;Recently I had to quickly test and deploy CentOS on 128 physical nodes,
just to test hardware and that all currently "supported" CentOS releases
could be installed quickly when needed. The interesting bit is that it
was a completely new infra, without any traditional deployment setup in
place, so obviously, as sysadmin, we directly think about pxe/kickstart,
which is so trivial to setup. That was the first time I had to "play"
with SeaMicro devices/chassis though, and so understanding how they work
(the SeaMicro &lt;a href="http://www.seamicro.com/SM15000"&gt;15K fabric chassis&lt;/a&gt;, to
be precise). One thing to note is that those seamicro chassis don't
provide remote VGA/KVM feature (but who cares, as we'll automate the
whole thing, right ? ) but they instead provide either cli (ssh) or rest
api access to the management interface, so that you can quickly
reset/reconfigure a node, changing vlan assignement, and so on.&lt;/p&gt;
&lt;p&gt;It's not a secret that I like to use &lt;a href="http://www.ansible.com/"&gt;Ansible&lt;/a&gt;
for ad-hoc tasks, and I thought that it would be (again) a good tool for
that quick task. If you have used Ansible already, you know that you
have to declare nodes and variables (not needed, but really useful) in
the inventory (if …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Recently I had to quickly test and deploy CentOS on 128 physical nodes,
just to test hardware and that all currently "supported" CentOS releases
could be installed quickly when needed. The interesting bit is that it
was a completely new infra, without any traditional deployment setup in
place, so obviously, as sysadmin, we directly think about pxe/kickstart,
which is so trivial to setup. That was the first time I had to "play"
with SeaMicro devices/chassis though, and so understanding how they work
(the SeaMicro &lt;a href="http://www.seamicro.com/SM15000"&gt;15K fabric chassis&lt;/a&gt;, to
be precise). One thing to note is that those seamicro chassis don't
provide remote VGA/KVM feature (but who cares, as we'll automate the
whole thing, right ? ) but they instead provide either cli (ssh) or rest
api access to the management interface, so that you can quickly
reset/reconfigure a node, changing vlan assignement, and so on.&lt;/p&gt;
&lt;p&gt;It's not a secret that I like to use &lt;a href="http://www.ansible.com/"&gt;Ansible&lt;/a&gt;
for ad-hoc tasks, and I thought that it would be (again) a good tool for
that quick task. If you have used Ansible already, you know that you
have to declare nodes and variables (not needed, but really useful) in
the inventory (if you don't gather inventory from an external source).
To configure my pxe setup (and so being able to reconfigure it when
needed) I obviously needed to get mac addresses from all 64 nodes in
each chassis, decide that hostnames will be n${slot-number}., etc ..
(and yes in Seamicro slot 1 = 0/0, slot 2 = 1/0, and so on ...)&lt;/p&gt;
&lt;p&gt;The following quick-and-dirty bash script let you do that quickly in 2
seconds (ssh into chassis, gather information, and fill some variables
in my ansible host_vars/${hostname} file) :&lt;/p&gt;
&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;1
2
3
4
5
6
7
8&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="ch"&gt;#!/bin/bash  &lt;/span&gt;
ssh admin@hufty.ci.centos.org &lt;span class="s2"&gt;&amp;quot;enable ; show server summary | include Intel ; quit&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="nb"&gt;read&lt;/span&gt; line &lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="k"&gt;do&lt;/span&gt;  
  &lt;span class="nv"&gt;seamicrosrvid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="se"&gt;\$&lt;/span&gt;line &lt;span class="p"&gt;|&lt;/span&gt;awk &lt;span class="s1"&gt;&amp;#39;{print \$1}&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;  
  &lt;span class="nv"&gt;slot&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="se"&gt;\$&lt;/span&gt;seamicrosrvid&lt;span class="p"&gt;|&lt;/span&gt; cut -f &lt;span class="m"&gt;1&lt;/span&gt; -d &lt;span class="s1"&gt;&amp;#39;/&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;  
  &lt;span class="nv"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt; &lt;span class="se"&gt;\$&lt;/span&gt;slot + &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;ip&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;id &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;mac&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="se"&gt;\$&lt;/span&gt;line &lt;span class="p"&gt;|&lt;/span&gt;awk &lt;span class="s1"&gt;&amp;#39;{print \$3}&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;  
  &lt;span class="nb"&gt;echo&lt;/span&gt; -e &lt;span class="s2"&gt;&amp;quot;name: n&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.hufty.ci.centos.org \nseamicro_chassis: hufty \nseamicro_srvid: &lt;/span&gt;&lt;span class="nv"&gt;$seamicrosrvid&lt;/span&gt;&lt;span class="s2"&gt; \nmac_address: &lt;/span&gt;&lt;span class="nv"&gt;$mac&lt;/span&gt;&lt;span class="s2"&gt; \nip: 172.19.3.&lt;/span&gt;&lt;span class="nv"&gt;$ip&lt;/span&gt;&lt;span class="s2"&gt; \ngateway: 172.19.3.254 \nnetmask: 255.255.252.0 \nnameserver: 172.19.0.12 \ncentos_dist: 6&amp;quot;&lt;/span&gt; &amp;gt;  inventory/n&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;.hufty.ci.centos.org  
&lt;span class="k"&gt;done&lt;/span&gt;  
&lt;/pre&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;Nice so we have all \~/ansible/hosts/host_vars/${inventory_hostname}
files in one go (I let you add ${inventory_hostname} in the
\~/ansible/hosts/hosts.cfg file with the same script, but modify to your
needs&lt;br&gt;
For the next step, we assume that we already have dnsmasq installed on
the "head" node, and that we also have a httpd setup to provide the
kickstart to the nodes during installation.&lt;br&gt;
So our basic ansible playbook looks like this :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gd"&gt;---  &lt;/span&gt;
&lt;span class="gd"&gt;- hosts: ci-nodes  &lt;/span&gt;
  sudo: True  
  gather_facts: False

  vars:  
    deploy_node: admin.ci.centos.org  
    seamicro_user_login: admin  
    seamicro_user_pass: obviously-hidden-and-changed  
    seamicro_reset_body:  
    action: reset  
    using-pxe: &amp;quot;true&amp;quot;  
    username: &amp;quot;{{ seamicro_user_login }}&amp;quot;  
    password: &amp;quot;{{ seamicro_user_pass }}&amp;quot;

  tasks:  
    - name: Generate kickstart file[s] for Seamicro node[s]  
      template: src=../templates/kickstarts/ci-centos-{{ centos_dist}}-ks.j2 dest=/var/www/html/ks/{{ inventory_hostname }}-ks.cfg mode=0755  
      delegate_to: &amp;quot;{{ deploy_node }}&amp;quot;

    - name: Adding the entry in DNS (dnsmasq)  
      lineinfile: dest=/etc/hosts regexp=&amp;quot;\^{{ ip }} {{ inventory_hostname }}&amp;quot; line=&amp;quot;{{ ip }} {{ inventory_hostname }}&amp;quot;  
      delegate_to: &amp;quot;{{ deploy_node }}&amp;quot;  
      notify: reload_dnsmasq

    - name: Adding the DHCP entry in dnsmasq  
      template: src=../templates/dnsmasq-dhcp.j2 dest=/etc/dnsmasq.d/{{ inventory_hostname }}.conf  
      delegate_to: &amp;quot;{{ deploy_node }}&amp;quot;  
      register: dhcpdnsmasq

    - name: Reloading dnsmasq configuration  
      service: name=dnsmasq state=restarted  
      run_once: true  
      when: dhcpdnsmasq|changed  
      delegate_to: &amp;quot;{{ deploy_node }}&amp;quot;

    - name: Generating the tftp configuration boot file  
      template: src=../templates/pxeboot-ci dest=/var/lib/tftpboot/pxelinux.cfg/01-{{ mac_address | lower | replace(&amp;quot;:&amp;quot;,&amp;quot;-&amp;quot;) }} mode=0755  
      delegate_to: &amp;quot;{{ deploy_node }}&amp;quot;

    - name: Resetting the Seamicro node[s]  
      uri: url=https://{{ seamicro_chassis }}.ci.centos.org/v2.0/server/{{ seamicro_srvid }}  
           method=POST  
           HEADER_Content-Type=&amp;quot;application/json&amp;quot;  
           body=&amp;#39;{{ seamicro_reset_body | to_json }}&amp;#39;  
           timeout=60  
      delegate_to: &amp;quot;{{ deploy_node }}&amp;quot;

    - name: Waiting for Seamicro node[s] to be available through ssh ...  
      action: wait_for port=22 host={{ inventory_hostname }} timeout=1200  
      delegate_to: &amp;quot;{{ deploy_node }}&amp;quot;

  handlers:  
    - name: reload_dnsmasq  
      service: name=dnsmasq state=reloaded  
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The first thing to notice is that you can use Ansible to provision nodes
that aren't already running : people think than ansible is just to
interact with already provisioned and running nodes, but by providing
useful informations in the inventory, and by delegating actions, we can
already start "managing" those yet-to-come nodes.&lt;br&gt;
All the templates used in that playbook are really basic ones, so
nothing "rocket science". For example the only diff for the kickstart.j2
template is that we inject ansible variables (for network and storage) :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="x"&gt;network --bootproto=static --device=eth0 --gateway=&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;gateway&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;span class="x"&gt;--ip=&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;ip&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt; --nameserver=&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;nameserver&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt; --netmask=&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;netmask&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt;&lt;/span&gt;
&lt;span class="x"&gt;--ipv6=auto --activate  &lt;/span&gt;
&lt;span class="x"&gt;network --hostname=&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;inventory_hostname&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt;  &lt;/span&gt;
&lt;span class="x"&gt;\&amp;lt;snip\&amp;gt;  &lt;/span&gt;
&lt;span class="x"&gt;part /boot --fstype=&amp;quot;ext4&amp;quot; --ondisk=sda --size=500  &lt;/span&gt;
&lt;span class="x"&gt;part pv.14 --fstype=&amp;quot;lvmpv&amp;quot; --ondisk=sda --size=10000 --grow  &lt;/span&gt;
&lt;span class="x"&gt;volgroup vg_&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;inventory_hostname_short&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt; --pesize=4096 pv.14  &lt;/span&gt;
&lt;span class="x"&gt;logvol /home --fstype=&amp;quot;xfs&amp;quot; --size=2412 --name=home --vgname=vg_&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt;
&lt;span class="nv"&gt;inventory_hostname_short&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt; --grow --maxsize=100000  &lt;/span&gt;
&lt;span class="x"&gt;logvol / --fstype=&amp;quot;xfs&amp;quot; --size=8200 --name=root --vgname=vg_&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt;
&lt;span class="nv"&gt;inventory_hostname_short&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt; --grow --maxsize=1000000  &lt;/span&gt;
&lt;span class="x"&gt;logvol swap --fstype=&amp;quot;swap&amp;quot; --size=2136 --name=swap --vgname=vg_&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt;
&lt;span class="nv"&gt;inventory_hostname_short&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt;  &lt;/span&gt;
&lt;span class="x"&gt;\&amp;lt;snip\&amp;gt;  &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The dhcp step isn't mandatory, but at least in that subnet we only allow
dhcp to "already known" mac address, retrieved from the ansible
inventory (and previously fetched directly from the seamicro chassis) :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="x"&gt;# &lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt; ip assignement  &lt;/span&gt;
&lt;span class="x"&gt;dhcp-host=&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;mac_address&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt;,&lt;/span&gt;&lt;span class="cp"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;ip&lt;/span&gt; &lt;span class="cp"&gt;}}&lt;/span&gt;&lt;span class="x"&gt;  &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Same thing for the pxelinux tftp config file :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;SERIAL&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;9600&lt;/span&gt;  
&lt;span class="nv"&gt;DEFAULT&lt;/span&gt; &lt;span class="nv"&gt;text&lt;/span&gt;  
&lt;span class="nv"&gt;PROMPT&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;  
&lt;span class="nb"&gt;TIMEOUT&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;  
&lt;span class="nv"&gt;TOTALTIMEOUT&lt;/span&gt; &lt;span class="mi"&gt;6000&lt;/span&gt;  
&lt;span class="nv"&gt;ONTIMEOUT&lt;/span&gt; {{ &lt;span class="nv"&gt;inventory_hostname&lt;/span&gt; }}&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;deploy&lt;/span&gt;

&lt;span class="nv"&gt;LABEL&lt;/span&gt; &lt;span class="nv"&gt;local&lt;/span&gt;  
&lt;span class="nv"&gt;MENU&lt;/span&gt; &lt;span class="nv"&gt;LABEL&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;local&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;  
&lt;span class="nv"&gt;MENU&lt;/span&gt; &lt;span class="nv"&gt;DEFAULT&lt;/span&gt;  
&lt;span class="nv"&gt;LOCALBOOT&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

&lt;span class="nv"&gt;LABEL&lt;/span&gt; {{ &lt;span class="nv"&gt;inventory_hostname&lt;/span&gt;}}&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;deploy&lt;/span&gt;  
&lt;span class="nv"&gt;kernel&lt;/span&gt; &lt;span class="nv"&gt;CentOS&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;{{ &lt;span class="nv"&gt;centos_dist&lt;/span&gt; }}&lt;span class="o"&gt;/&lt;/span&gt;{{ &lt;span class="nv"&gt;centos_arch&lt;/span&gt;}}&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;vmlinuz&lt;/span&gt;  
&lt;span class="nv"&gt;MENU&lt;/span&gt; &lt;span class="nv"&gt;LABEL&lt;/span&gt; &lt;span class="nv"&gt;CentOS&lt;/span&gt; {{ &lt;span class="nv"&gt;centos_dist&lt;/span&gt; }} {{ &lt;span class="nv"&gt;centos_arch&lt;/span&gt; }}&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;CI&lt;/span&gt; &lt;span class="nv"&gt;Kickstart&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; {{ &lt;span class="nv"&gt;inventory_hostname&lt;/span&gt; }}  
{&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;centos_dist&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="o"&gt;-%&lt;/span&gt;}  
&lt;span class="nv"&gt;append&lt;/span&gt; &lt;span class="nv"&gt;initrd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;CentOS&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;{{ &lt;span class="nv"&gt;centos_arch&lt;/span&gt; }}&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;initrd&lt;/span&gt;.&lt;span class="nv"&gt;img&lt;/span&gt; &lt;span class="nv"&gt;net&lt;/span&gt;.&lt;span class="nv"&gt;ifnames&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="nv"&gt;biosdevname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="nv"&gt;ip&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;eth0&lt;/span&gt;:&lt;span class="nv"&gt;dhcp&lt;/span&gt; &lt;span class="nv"&gt;inst&lt;/span&gt;.&lt;span class="nv"&gt;ks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;http&lt;/span&gt;:&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;admin&lt;/span&gt;.&lt;span class="nv"&gt;ci&lt;/span&gt;.&lt;span class="nv"&gt;centos&lt;/span&gt;.&lt;span class="nv"&gt;org&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;ks&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;{{ &lt;span class="nv"&gt;inventory_hostname&lt;/span&gt; }}&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;ks&lt;/span&gt;.&lt;span class="nv"&gt;cfg&lt;/span&gt; &lt;span class="nv"&gt;console&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;ttyS0&lt;/span&gt;,&lt;span class="mi"&gt;9600&lt;/span&gt;&lt;span class="nv"&gt;n8&lt;/span&gt;  
{&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;-%&lt;/span&gt;}  
&lt;span class="nv"&gt;append&lt;/span&gt; &lt;span class="nv"&gt;initrd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;CentOS&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;{{ &lt;span class="nv"&gt;centos_dist&lt;/span&gt; }}&lt;span class="o"&gt;/&lt;/span&gt;{{ &lt;span class="nv"&gt;centos_arch&lt;/span&gt; }}&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;initrd&lt;/span&gt;.&lt;span class="nv"&gt;img&lt;/span&gt; &lt;span class="nv"&gt;ksdevice&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;eth0&lt;/span&gt; &lt;span class="nv"&gt;ip&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;dhcp&lt;/span&gt; &lt;span class="nv"&gt;ks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;http&lt;/span&gt;:&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;admin&lt;/span&gt;.&lt;span class="nv"&gt;ci&lt;/span&gt;.&lt;span class="nv"&gt;centos&lt;/span&gt;.&lt;span class="nv"&gt;org&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;ks&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;{{ &lt;span class="nv"&gt;inventory_hostname&lt;/span&gt; }}&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;ks&lt;/span&gt;.&lt;span class="nv"&gt;cfg&lt;/span&gt; &lt;span class="nv"&gt;console&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;ttyS0&lt;/span&gt;,&lt;span class="mi"&gt;9600&lt;/span&gt;&lt;span class="nv"&gt;n8&lt;/span&gt;  
{&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;endif&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;}  
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The interesting part is the one on which I needed to spend more time :
as said, it was the first time I had to play with SeaMicro hardware, so
I had to dive into documentation (which I *always* do, RTFM FTW !) and
understand how to use their &lt;a href="http://en.wikipedia.org/wiki/Representational_state_transfer"&gt;Rest
API&lt;/a&gt; but
once done, it was a breeze. Ansible by default doesn't provide a native
resource for Seamicro, but that's why Rest exists, right and thanfully,
Ansible has a native &lt;a href="http://docs.ansible.com/uri_module.html"&gt;URI
module&lt;/a&gt;, which we use here .
The only thing on which I had to spend more time was to understand how
to properly construct the body, but declaring in the yaml file as a
variable/list and then converting it on the fly to json (with the
magical &lt;em&gt;body='{{ seamicro_reset_body | to_json }}'&lt;/em&gt; ) was the way to
go and is so self-explained when read now.&lt;/p&gt;
&lt;p&gt;And here we go, calling that ansible playbook and suddenly 128 physical
machines were being installed (and reinstalled with different CentOS
versions - 5,6,7 - and arches i386,x86_64)&lt;/p&gt;
&lt;p&gt;Hope this helps if you  have to interact with Seamicro chassis from
within an ansible playbook too&lt;/p&gt;</content><category term="Ansible"></category><category term="CentOS"></category><category term="Cluster"></category><category term="SysAdmin"></category><category term="Uncategorized"></category></entry><entry><title>Debug for the winners !</title><link href="https://arrfab.net/posts/2013/Oct/31/debug-for-the-winners/" rel="alternate"></link><published>2013-10-31T16:33:00+01:00</published><updated>2013-10-31T16:33:00+01:00</updated><author><name>Fabian Arrotin</name></author><id>tag:arrfab.net,2013-10-31:/posts/2013/Oct/31/debug-for-the-winners/</id><summary type="html">&lt;p&gt;Recently I had to dive back into &lt;a href="http://www.ansibleworks.com/"&gt;Ansible&lt;/a&gt;
playbooks I wrote (quite) some time ago. I had to add some logic to
generate different application templates based on facts/packages being
installed on the managed nodes. Long story short (I'll not describe the
use case here as it's quite complex), I decided that injecting directly
some kind of &lt;a href="http://jinja.pocoo.org/docs/templates/#filters"&gt;logic in the Jinja2
templates&lt;/a&gt; was enough ..
but not.&lt;/p&gt;
&lt;p&gt;Let's take a very simplified example here (don't even look at the tasks
but rather at the logic explained how to get there, once again this is a
'stupid' playbook) :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gd"&gt;---  &lt;/span&gt;
&lt;span class="gd"&gt;- hosts: localhost  &lt;/span&gt;
  connection: local  
  user: root  
  vars:  
    - myrole: httpserver

  tasks:  
    - name: registering a variable only if myrole is httpserver  
      command: /bin/rpm -q --qf &amp;#39;%{version}&amp;#39; httpd  
      register: httpd_version  
      when: myrole == &amp;#39;httpserver&amp;#39;  
    - name: pushing the generated template  
      template: src=../templates/logic.txt.j2 dest=/tmp/logic.txt

 handlers:
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now let's have a look at the (very) simple logic.txt.j2 :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;{&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;httpd_version&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;defined&lt;/span&gt; &lt;span class="o"&gt;-%&lt;/span&gt;}  
 &lt;span class="nv"&gt;You&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="s"&gt;re using an Apache http server version : {{ httpd_version.stdout&amp;gt; }}  &lt;/span&gt;
{&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;}  
  &lt;span class="nv"&gt;You&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="s"&gt;re not using an http server, or not defined in the ansible&amp;gt; machine role  &lt;/span&gt;
{&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;endif&lt;/span&gt; &lt;span class="o"&gt;-%&lt;/span&gt;}
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Easy, and it seems it was working when myrole was indeed httpserver :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;cat …&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;</summary><content type="html">&lt;p&gt;Recently I had to dive back into &lt;a href="http://www.ansibleworks.com/"&gt;Ansible&lt;/a&gt;
playbooks I wrote (quite) some time ago. I had to add some logic to
generate different application templates based on facts/packages being
installed on the managed nodes. Long story short (I'll not describe the
use case here as it's quite complex), I decided that injecting directly
some kind of &lt;a href="http://jinja.pocoo.org/docs/templates/#filters"&gt;logic in the Jinja2
templates&lt;/a&gt; was enough ..
but not.&lt;/p&gt;
&lt;p&gt;Let's take a very simplified example here (don't even look at the tasks
but rather at the logic explained how to get there, once again this is a
'stupid' playbook) :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gd"&gt;---  &lt;/span&gt;
&lt;span class="gd"&gt;- hosts: localhost  &lt;/span&gt;
  connection: local  
  user: root  
  vars:  
    - myrole: httpserver

  tasks:  
    - name: registering a variable only if myrole is httpserver  
      command: /bin/rpm -q --qf &amp;#39;%{version}&amp;#39; httpd  
      register: httpd_version  
      when: myrole == &amp;#39;httpserver&amp;#39;  
    - name: pushing the generated template  
      template: src=../templates/logic.txt.j2 dest=/tmp/logic.txt

 handlers:
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now let's have a look at the (very) simple logic.txt.j2 :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;{&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;httpd_version&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;defined&lt;/span&gt; &lt;span class="o"&gt;-%&lt;/span&gt;}  
 &lt;span class="nv"&gt;You&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="s"&gt;re using an Apache http server version : {{ httpd_version.stdout&amp;gt; }}  &lt;/span&gt;
{&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;}  
  &lt;span class="nv"&gt;You&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="s"&gt;re not using an http server, or not defined in the ansible&amp;gt; machine role  &lt;/span&gt;
{&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;endif&lt;/span&gt; &lt;span class="o"&gt;-%&lt;/span&gt;}
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Easy, and it seems it was working when myrole was indeed httpserver :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;tmp&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;logic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;txt&lt;/span&gt;  
  &lt;span class="n"&gt;You&lt;/span&gt;&lt;span class="err"&gt;&amp;#39;&lt;/span&gt;&lt;span class="n"&gt;re&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="n"&gt;an&lt;/span&gt; &lt;span class="n"&gt;Apache&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt; &lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="k"&gt;version&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;But things didn't work as expected when myrole was something else, like
for example dbserver&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="nv"&gt;TASK&lt;/span&gt;: [&lt;span class="nv"&gt;registering&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;variable&lt;/span&gt; &lt;span class="nv"&gt;only&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;myrole&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;httpserver&lt;/span&gt;]
 \&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;  
  &lt;span class="nv"&gt;skipping&lt;/span&gt;: [&lt;span class="nv"&gt;localhost&lt;/span&gt;]

 &lt;span class="nv"&gt;TASK&lt;/span&gt;: [&lt;span class="nv"&gt;pushing&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;generated&lt;/span&gt; &lt;span class="nv"&gt;template&lt;/span&gt;]
 \&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;\&lt;span class="o"&gt;*&lt;/span&gt;  
  &lt;span class="nv"&gt;fatal&lt;/span&gt;: [&lt;span class="nv"&gt;localhost&lt;/span&gt;] &lt;span class="o"&gt;=&lt;/span&gt;\&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; {&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="s"&gt;msg&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;: &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="s"&gt;One or more undefined variables:&lt;/span&gt;
 &lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="s"&gt;dict&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt; &lt;span class="nv"&gt;object&lt;/span&gt; &lt;span class="nv"&gt;has&lt;/span&gt; &lt;span class="nv"&gt;no&lt;/span&gt; &lt;span class="nv"&gt;attribute&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="s"&gt;stdout&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="s"&gt;, &amp;#39;failed&amp;#39;: True}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;hmm, as the register: task was skipped, I was wondering why it then
complained about the httpd_version.stdout as I thought that
httpd_version wasn't defined .. but I was wrong  : even if 'skipped'
the variable exists for that host. I quickly discovered it when adding a
&lt;a href="http://www.ansibleworks.com/docs/modules.html#debug"&gt;debug&lt;/a&gt; task in
between the other tasks in my playbook :&lt;/p&gt;
&lt;p&gt;&lt;code&gt;- debug: msg="this is http_version value {{ httpd_version }}"&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now let's see what can be wrong :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;TASK&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;debug msg=&amp;quot;this is http_version value {{httpd_version}}&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;localhost&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;&amp;quot;msg&amp;quot;&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ss"&gt;&amp;quot;this is http_version value {u&amp;#39;skipped&amp;#39;: True, u&amp;#39;changed&amp;#39;: False}&amp;quot;&lt;/span&gt;&lt;span class="err"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Very interesting : so even when skipped, the variable httpd_version is
still "registered" by the register: feature but marked as skipped.&lt;/p&gt;
&lt;p&gt;Let's so change our "logic" in the Jinja2 template then ! :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;{&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nv"&gt;httpd_version&lt;/span&gt;.&lt;span class="nv"&gt;skipped&lt;/span&gt; &lt;span class="o"&gt;-%&lt;/span&gt;}  
  &lt;span class="nv"&gt;You&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="s"&gt;re not using an http server, or not defined in the ansible machine role  &lt;/span&gt;
{&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt;}  
  &lt;span class="nv"&gt;You&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="s"&gt;re using an Apache http server version : {{ httpd_version.stdout }}  &lt;/span&gt;
{&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="k"&gt;endif&lt;/span&gt; &lt;span class="o"&gt;-%&lt;/span&gt;}
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;And now it works in all cases ..&lt;/p&gt;
&lt;p&gt;It's a (very,very,very) simplified example, but you get the idea and
using the debug module (don't forget to call ansible-playbook with -vvv
to see those messages too !) can quickly show you where your issue is
when having to troubleshoot something. As &lt;a href="http://www.jedi.be/"&gt;Patrick
Debois&lt;/a&gt; was &lt;a href="https://twitter.com/patrickdebois/status/390719078367002624"&gt;saying&lt;/a&gt; : "you gotta love Ansible for its simplicity" :-)&lt;/p&gt;</content><category term="Ansible"></category><category term="CentOS"></category><category term="SysAdmin"></category></entry><entry><title>Rolling updates with Ansible and Apache reverse proxies</title><link href="https://arrfab.net/posts/2013/May/23/rolling-updates-with-ansible-and-apache-reverse-proxies/" rel="alternate"></link><published>2013-05-23T17:36:00+02:00</published><updated>2013-05-23T17:36:00+02:00</updated><author><name>Fabian Arrotin</name></author><id>tag:arrfab.net,2013-05-23:/posts/2013/May/23/rolling-updates-with-ansible-and-apache-reverse-proxies/</id><summary type="html">&lt;p&gt;It's not a secret anymore that I use &lt;a href="http://ansible.cc/"&gt;Ansible&lt;/a&gt; to do
a lot of things. That goes from simple "one shot" actions with ansible
on multiple nodes to "configuration management and deployment tasks"
with ansible-playbook. One of the thing I also really like with Ansible
is the fact that it's also a great
&lt;a href="http://en.wikipedia.org/wiki/Orchestration_%28computing%29"&gt;orchestration&lt;/a&gt;
tool.&lt;/p&gt;
&lt;p&gt;For example, in some WSOA flows you can have a bunch of servers behind
load balancer nodes. When you want to put a backend node/web server node
in maintenance mode (to change configuration/update package/update
app/whatever), you just "remove" that node from the production flow, do
what you need to do, verify it's up again and put that node back in
production. The principle of "rolling updates" is then interesting as
you still have 24/7 flows in production.&lt;/p&gt;
&lt;p&gt;But what if you're not in charge of the whole infrastructure ? AKA for
example you're in charge of some servers, but not the load balancers in
front of your infrastructure. Let's consider the following situation,
and how we'll use ansible to still disable/enable a backend server
behind Apache reverse proxies.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Apache LB" src="/images/Apache-LB1.png" title="Apache-LB"&gt;&lt;/p&gt;
&lt;p&gt;So here is the (simplified) situation : two Apache reverse proxies
(using the …&lt;/p&gt;</summary><content type="html">&lt;p&gt;It's not a secret anymore that I use &lt;a href="http://ansible.cc/"&gt;Ansible&lt;/a&gt; to do
a lot of things. That goes from simple "one shot" actions with ansible
on multiple nodes to "configuration management and deployment tasks"
with ansible-playbook. One of the thing I also really like with Ansible
is the fact that it's also a great
&lt;a href="http://en.wikipedia.org/wiki/Orchestration_%28computing%29"&gt;orchestration&lt;/a&gt;
tool.&lt;/p&gt;
&lt;p&gt;For example, in some WSOA flows you can have a bunch of servers behind
load balancer nodes. When you want to put a backend node/web server node
in maintenance mode (to change configuration/update package/update
app/whatever), you just "remove" that node from the production flow, do
what you need to do, verify it's up again and put that node back in
production. The principle of "rolling updates" is then interesting as
you still have 24/7 flows in production.&lt;/p&gt;
&lt;p&gt;But what if you're not in charge of the whole infrastructure ? AKA for
example you're in charge of some servers, but not the load balancers in
front of your infrastructure. Let's consider the following situation,
and how we'll use ansible to still disable/enable a backend server
behind Apache reverse proxies.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Apache LB" src="/images/Apache-LB1.png" title="Apache-LB"&gt;&lt;/p&gt;
&lt;p&gt;So here is the (simplified) situation : two Apache reverse proxies
(using the
&lt;a href="http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html"&gt;mod_proxy_balancer&lt;/a&gt;
module) are used to load balance traffic to four backend nodes (Jboss in
our simplified case). We can't directly touch those upstream Apache
nodes, but we can still interact on them , thanks to the fact that
"&lt;a href="http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html#balancer_manager"&gt;balancer manager
suppor&lt;/a&gt;t"
is active (and protected !)&lt;/p&gt;
&lt;p&gt;Let's have a look at a (simplified) ansible inventory file :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;[jboss-cluster]&lt;/span&gt;
&lt;span class="na"&gt;jboss-1&lt;/span&gt;
&lt;span class="na"&gt;jboss-2&lt;/span&gt;
&lt;span class="na"&gt;jboss-3&lt;/span&gt;
&lt;span class="na"&gt;jboss-4&lt;/span&gt;
&lt;span class="k"&gt;[apache-group-1]&lt;/span&gt;
&lt;span class="na"&gt;apache-node-1&lt;/span&gt;
&lt;span class="na"&gt;apache-node-2&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Let's now create a generic (write once/use it many) task to disable a
backend node from apache ! :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;---&lt;/span&gt;
##############################################################################
#
# &lt;span class="nv"&gt;This&lt;/span&gt; &lt;span class="nv"&gt;task&lt;/span&gt; &lt;span class="nv"&gt;can&lt;/span&gt; &lt;span class="nv"&gt;be&lt;/span&gt; &lt;span class="nv"&gt;included&lt;/span&gt; &lt;span class="nv"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;playbook&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="k"&gt;pause&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;backend&lt;/span&gt; &lt;span class="nv"&gt;node&lt;/span&gt;
# &lt;span class="nv"&gt;being&lt;/span&gt; &lt;span class="nv"&gt;load&lt;/span&gt; &lt;span class="nv"&gt;balanced&lt;/span&gt; &lt;span class="nv"&gt;by&lt;/span&gt; &lt;span class="nv"&gt;Apache&lt;/span&gt; &lt;span class="nv"&gt;Reverse&lt;/span&gt; &lt;span class="nv"&gt;Proxies&lt;/span&gt;
# &lt;span class="nv"&gt;Two&lt;/span&gt; &lt;span class="nv"&gt;variables&lt;/span&gt; &lt;span class="nv"&gt;need&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;be&lt;/span&gt; &lt;span class="nv"&gt;defined&lt;/span&gt; : 
#   &lt;span class="o"&gt;-&lt;/span&gt; ${&lt;span class="nv"&gt;apache_rp_backend_url&lt;/span&gt;} : &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;URL&lt;/span&gt; &lt;span class="nv"&gt;of&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;backend&lt;/span&gt; &lt;span class="nv"&gt;server&lt;/span&gt;, &lt;span class="nv"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;known&lt;/span&gt; &lt;span class="nv"&gt;by&lt;/span&gt; &lt;span class="nv"&gt;Apache&lt;/span&gt; &lt;span class="nv"&gt;server&lt;/span&gt;
#   &lt;span class="o"&gt;-&lt;/span&gt; ${&lt;span class="nv"&gt;apache_rp_backend_cluster&lt;/span&gt;} : &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="nv"&gt;of&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;cluster&lt;/span&gt; &lt;span class="nv"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;defined&lt;/span&gt; &lt;span class="nv"&gt;on&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;Apache&lt;/span&gt; &lt;span class="nv"&gt;RP&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;group&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;node&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;member&lt;/span&gt; &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;internalasync&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
#   &lt;span class="o"&gt;-&lt;/span&gt; ${&lt;span class="nv"&gt;apache_rp_group&lt;/span&gt;} : &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="nv"&gt;of&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;group&lt;/span&gt; &lt;span class="nv"&gt;declared&lt;/span&gt; &lt;span class="nv"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;hosts&lt;/span&gt;.&lt;span class="nv"&gt;cfg&lt;/span&gt; &lt;span class="nv"&gt;containing&lt;/span&gt; &lt;span class="nv"&gt;Apache&lt;/span&gt; &lt;span class="nv"&gt;Reverse&lt;/span&gt; &lt;span class="nv"&gt;Proxies&lt;/span&gt;
#   &lt;span class="o"&gt;-&lt;/span&gt; ${&lt;span class="nv"&gt;apache_rp_user&lt;/span&gt;}: &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;username&lt;/span&gt; &lt;span class="nv"&gt;used&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;authenticate&lt;/span&gt; &lt;span class="nv"&gt;against&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;Apache&lt;/span&gt; &lt;span class="nv"&gt;balancer&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;manager&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;clusteradmin&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
#   &lt;span class="o"&gt;-&lt;/span&gt; ${&lt;span class="nv"&gt;apache_rp_password&lt;/span&gt;}: &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;password&lt;/span&gt; &lt;span class="nv"&gt;used&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;authenticate&lt;/span&gt; &lt;span class="nv"&gt;against&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;Apache&lt;/span&gt; &lt;span class="nv"&gt;balancer&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;manager&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="nv"&gt;added592b&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
#   &lt;span class="o"&gt;-&lt;/span&gt; ${&lt;span class="nv"&gt;apache_rp_balancer_manager_uri&lt;/span&gt;}: &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;URI&lt;/span&gt; &lt;span class="nv"&gt;where&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;find&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;balancer&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;manager&lt;/span&gt; &lt;span class="nv"&gt;Apache&lt;/span&gt; &lt;span class="nv"&gt;mod&lt;/span&gt;
#
##############################################################################
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;: &lt;span class="nv"&gt;Disabling&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;worker&lt;/span&gt; &lt;span class="nv"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;Apache&lt;/span&gt; &lt;span class="nv"&gt;Reverse&lt;/span&gt; &lt;span class="nv"&gt;Proxies&lt;/span&gt;
  &lt;span class="nv"&gt;local_action&lt;/span&gt;: &lt;span class="nv"&gt;shell&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;curl&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;k&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nv"&gt;user&lt;/span&gt; ${&lt;span class="nv"&gt;apache_rp_user&lt;/span&gt;}:${&lt;span class="nv"&gt;apache_rp_password&lt;/span&gt;} &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="s"&gt;https://${item}/${apache_rp_balancer_manager_uri}?b=${apache_rp_backend_cluster}&amp;amp;w=${apache_rp_backend_url}&amp;amp;nonce=$(curl -k --user ${apache_rp_user}:${apache_rp_password} https://${item}/${apache_rp_balancer_manager_uri} |grep nonce|tail -n 1|cut -f 3 -d &amp;#39;&amp;amp;&amp;#39;|cut -f 2 -d &amp;#39;=&amp;#39;|cut -f 1 -d &amp;#39;&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="s"&gt;)&amp;amp;dw=Disable&amp;quot;&lt;/span&gt;
  &lt;span class="nv"&gt;with_items&lt;/span&gt;: ${&lt;span class="nv"&gt;groups&lt;/span&gt;.${&lt;span class="nv"&gt;apache_rp_group&lt;/span&gt;}}

&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;: &lt;span class="nv"&gt;Waiting&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="nv"&gt;seconds&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;be&lt;/span&gt; &lt;span class="nv"&gt;sure&lt;/span&gt; &lt;span class="nv"&gt;no&lt;/span&gt; &lt;span class="nv"&gt;traffic&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;being&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt; &lt;span class="nv"&gt;anymore&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;that&lt;/span&gt; &lt;span class="nv"&gt;worker&lt;/span&gt; &lt;span class="nv"&gt;backend&lt;/span&gt; &lt;span class="nv"&gt;node&lt;/span&gt;
  &lt;span class="k"&gt;pause&lt;/span&gt;: &lt;span class="nv"&gt;seconds&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The interesting bit is the with_items one : it will use the
apache_rp_group variable to know which apache servers are used
upstream (assuming you can have multiple nodes/clusters) and will play
that command for every host in the list obtained from the inventory !&lt;/p&gt;
&lt;p&gt;We can now, in the "rolling-updates" playbook, just call the previous
tasks (assuming we saved it as ../tasks/apache-disable-worker.yml) :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;---&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;hosts&lt;/span&gt;: &lt;span class="nv"&gt;jboss&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;cluster&lt;/span&gt;
  &lt;span class="nv"&gt;serial&lt;/span&gt;: &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="nv"&gt;user&lt;/span&gt;: &lt;span class="nv"&gt;root&lt;/span&gt;
  &lt;span class="nv"&gt;tasks&lt;/span&gt;:
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;include&lt;/span&gt;: ..&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;tasks&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;apache&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;disable&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;worker&lt;/span&gt;.&lt;span class="nv"&gt;yml&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;etc&lt;/span&gt; ...
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;wait_for&lt;/span&gt;: &lt;span class="nv"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;8443&lt;/span&gt; &lt;span class="nv"&gt;state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;started&lt;/span&gt;
  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;include&lt;/span&gt;: ..&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;tasks&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;apache&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;enable&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nv"&gt;worker&lt;/span&gt;.&lt;span class="nv"&gt;yml&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;But Wait ! As you've seen, we still need to declare some variables :
let's do that in the inventory, under group_vars and host_vars !&lt;/p&gt;
&lt;p&gt;group_vars/jboss-cluster :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt; &lt;span class="n"&gt;Apache&lt;/span&gt; &lt;span class="n"&gt;reverse&lt;/span&gt; &lt;span class="n"&gt;proxies&lt;/span&gt; &lt;span class="n"&gt;settins&lt;/span&gt;  
&lt;span class="n"&gt;apache_rp_group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;apache&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;group&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;  
&lt;span class="n"&gt;apache_rp_user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;my&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;admin&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;account&lt;/span&gt;  
&lt;span class="n"&gt;apache_rp_password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;my&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;beautiful&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;pass&lt;/span&gt;  
&lt;span class="n"&gt;apache_rp_balancer_manager_uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="n"&gt;balancer&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;manager&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hidden&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;and&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;redirected&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;host_vars/jboss-1 :&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;apache_rp_backend_url&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;https://jboss1.myinternal.domain.org:8443&amp;#39;&lt;/span&gt;  
&lt;span class="n"&gt;apache_rp_backend_cluster&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;nameofmyclusterdefinedinapache&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Now when we'll use that playbook, we'll have a local action that will
interact with the balancer manager to disable that backend node while we
do maintainance.&lt;/p&gt;
&lt;p&gt;I let you imagine (and create) a ../tasks/apache-enable-worker.yml file
to enable it (which you'll call at the end of your playbook).&lt;/p&gt;</content><category term="Ansible"></category><category term="CentOS"></category><category term="Cluster"></category><category term="Linux"></category><category term="SysAdmin"></category></entry><entry><title>Using Openssh as transport for Ansible instead of default paramiko</title><link href="https://arrfab.net/posts/2012/Oct/30/using-openssh-as-transport-for-ansible-instead-of-default-paramiko/" rel="alternate"></link><published>2012-10-30T14:35:00+01:00</published><updated>2012-10-30T14:35:00+01:00</updated><author><name>Fabian Arrotin</name></author><id>tag:arrfab.net,2012-10-30:/posts/2012/Oct/30/using-openssh-as-transport-for-ansible-instead-of-default-paramiko/</id><summary type="html">&lt;p&gt;You've probably read that&lt;a href="http://ansible.cc"&gt;Ansible&lt;/a&gt;uses by default
&lt;a href="http://www.lag.net/paramiko/"&gt;paramiko&lt;/a&gt;for the SSH connections to the
host(s) you want to manage. But since 0.5 (quite some ago now ...)
Ansible can use plain openssh binary as a transport. Why ? simple
reasons : you sometimes have complex scenario and you can for example
declare a &lt;a href="http://www.arrfab.net/blog/?p=246"&gt;ProxyCommand&lt;/a&gt;in your
\~/.ssh/config if you need to use a JumpHost to reach the real host you
want to connect to. That's fine and I was using that for some of the
hosts i have to managed (specifying -c ssh when calling ansible, but
having switched to a bash alias containing that string and also -i
/path/to/my/inventory for those hosts).&lt;/p&gt;
&lt;p&gt;It's great but it can lead to strange results if you don't have a full
look at what's happening in the background. Here is the situation I just
had yesterday : one of the remote hosts is reachable, but not a standard
port (aka tcp/22) so an entry in my \~/.ssh/config was containing both
HostName (for the known FQDN of the host I had to point to, not the host
i wanted to reach) and Port.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Host myremotehost&lt;br&gt;
 HostName
my.public.name …&lt;/p&gt;&lt;/blockquote&gt;</summary><content type="html">&lt;p&gt;You've probably read that&lt;a href="http://ansible.cc"&gt;Ansible&lt;/a&gt;uses by default
&lt;a href="http://www.lag.net/paramiko/"&gt;paramiko&lt;/a&gt;for the SSH connections to the
host(s) you want to manage. But since 0.5 (quite some ago now ...)
Ansible can use plain openssh binary as a transport. Why ? simple
reasons : you sometimes have complex scenario and you can for example
declare a &lt;a href="http://www.arrfab.net/blog/?p=246"&gt;ProxyCommand&lt;/a&gt;in your
\~/.ssh/config if you need to use a JumpHost to reach the real host you
want to connect to. That's fine and I was using that for some of the
hosts i have to managed (specifying -c ssh when calling ansible, but
having switched to a bash alias containing that string and also -i
/path/to/my/inventory for those hosts).&lt;/p&gt;
&lt;p&gt;It's great but it can lead to strange results if you don't have a full
look at what's happening in the background. Here is the situation I just
had yesterday : one of the remote hosts is reachable, but not a standard
port (aka tcp/22) so an entry in my \~/.ssh/config was containing both
HostName (for the known FQDN of the host I had to point to, not the host
i wanted to reach) and Port.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Host myremotehost&lt;br&gt;
 HostName
my.public.name.or.the.one.from.the.bastion.with.iptables.rule&lt;br&gt;
 Port 2222&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;With such entry, I was able to just "ssh user@myremotehost" and was
directly on the remote box. "ansible -c ssh  -m ping myremotehost" was
happy, but in fact was not reaching the host I was thinking : running
"ansible -c ssh -m setup myremotehost -vvv" showed me that ansible_fqdn
(one of the ansible facts) wasn't the correct one but instead the host
in front of that machine (the one declared with HostName in
\~/.ssh/config). The verbose mode showed me that even if you specify the
Port in your \~/.ssh/config, ansible will *always* use port 22 :&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;\&amp;lt;myremotehost&gt; EXEC ['ssh', '-tt', '-q', '-o', 'AddressFamily=inet',
'-o', 'ControlMaster=auto', '-o',
'ControlPath=/tmp/ansible-ssh-%h-%p-%r', '-o',
'StrictHostKeyChecking=no', '-o', 'Port=22', '-o', 'User=root',
'myremotehost', 'mkdir -p
/var/tmp/ansible-1351603527.81-16435744643257 &amp;amp;&amp;amp; echo
/var/tmp/ansible-1351603527.81-16435744643257']&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Hmm, quickly resolved : a quick discussion with people hanging in the
#ansible IRC channel (on irc.freenode.net) explained the issue to me :
Port is *never* being looked at in your \~/.ssh/config, even when
using -c ssh. Solution is to specify the port in your inventory file, as
a variable for that host :&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;myremotehost ansible_ssh_port=9999&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In the same vein, you can also use ansible_ssh_host , this one
corresponding to the HostName of your  \~/.ssh/config.&lt;/p&gt;
&lt;p&gt;Hope that it can save you time, if you encounter the same "issue" one
day ...&lt;/p&gt;</content><category term="Ansible"></category><category term="CentOS"></category><category term="SysAdmin"></category></entry><entry><title>Ansible as an alternative to puppet/chef/cfengine and others ...</title><link href="https://arrfab.net/posts/2012/Oct/26/ansible-as-an-alternative-to-puppetchefcfengine-and-others/" rel="alternate"></link><published>2012-10-26T15:02:00+02:00</published><updated>2012-10-26T15:02:00+02:00</updated><author><name>Fabian Arrotin</name></author><id>tag:arrfab.net,2012-10-26:/posts/2012/Oct/26/ansible-as-an-alternative-to-puppetchefcfengine-and-others/</id><summary type="html">&lt;p&gt;I already know that i'll be criticized for this post, but i don't care
:-) . Strangely my last blog post (which is *very* old ...) was about
a puppet dashboard, so why speaking about another tool ? Well, first i
got a new job and some prerequisites have changed. I still like puppet
(and I'd even want to be able to use puppet but that's another story
...) but I was faced to some constraints when being in front of a new
project. For that specific project,  I had to configure a bunch of new
Virtual Machines (RHEL6) coming as OVF files. Problem number one was
that I can't alter or modify the base image so i can't push packages
(from the distro or third-party repositories). Second issue is that I
can't install nor have a daemon/agent running on those machines. I had a
look at the different config tools available but they all require either
a daemon to be started, or at least having extra packages to be
installed on each managed node. (so not possible to have puppetd nor
puppetrun or invoke puppet directly through ssh , as
&lt;a href="http://www.puppetlabs.com/"&gt;puppet&lt;/a&gt; can't even be installed, same for
&lt;a href="http://saltstack.org/"&gt;saltstack&lt;/a&gt;). That's why i decided to give …&lt;/p&gt;</summary><content type="html">&lt;p&gt;I already know that i'll be criticized for this post, but i don't care
:-) . Strangely my last blog post (which is *very* old ...) was about
a puppet dashboard, so why speaking about another tool ? Well, first i
got a new job and some prerequisites have changed. I still like puppet
(and I'd even want to be able to use puppet but that's another story
...) but I was faced to some constraints when being in front of a new
project. For that specific project,  I had to configure a bunch of new
Virtual Machines (RHEL6) coming as OVF files. Problem number one was
that I can't alter or modify the base image so i can't push packages
(from the distro or third-party repositories). Second issue is that I
can't install nor have a daemon/agent running on those machines. I had a
look at the different config tools available but they all require either
a daemon to be started, or at least having extra packages to be
installed on each managed node. (so not possible to have puppetd nor
puppetrun or invoke puppet directly through ssh , as
&lt;a href="http://www.puppetlabs.com/"&gt;puppet&lt;/a&gt; can't even be installed, same for
&lt;a href="http://saltstack.org/"&gt;saltstack&lt;/a&gt;). That's why i decided to give
&lt;a href="http://ansible.cc"&gt;Ansible&lt;/a&gt; a try. It was already on my "TO-test" list
for a long time but it seems it was really fitting the bill for that
specific project and constraints : using the 'already-in-place' ssh
authorization, no packages to be installed on the managed nodes, and
last-but-no-least, a learning curve that is really thin (compared to
puppet and others, but that's my personal opinion/experience).&lt;/p&gt;
&lt;p&gt;The other good thing with Ansible is that you can start very easily and
then slowly add 'complexity' to your playbooks/tasks. I'm still using
for example a flat inventory file, but already organized to reflect what
we can do in the future (hostnames included in groups, themselves
included in parents groups - aka nested groups). Same for the variables
inheritance : at the group level and down to the host level, host
variables overwriting those defined at the group level , etc ...)&lt;/p&gt;
&lt;p&gt;The Yaml syntax is really easy to understand so you can have quickly
your first playbook being played on a bunch of machines simultaneously
(thanks to paramiko/parallel ssh). The number of modules is less than
the puppet resources, but is quickly growing. I also just tested to tie
the execution of ansible playbook with&lt;a href="http://jenkins-ci.org/"&gt;Jenkins&lt;/a&gt;
so that people not having access to the ansible
inventory/playbooks/tasks (stored in a vcs, subversion in my case) can
use it from a gui.. More to come on Ansible in the future&lt;/p&gt;</content><category term="Ansible"></category><category term="CentOS"></category><category term="Cluster"></category><category term="Linux"></category><category term="SysAdmin"></category></entry></feed>