<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>very nomagic</title>
    <description>Documenting stuff I haven't found anywhere else on the internet</description>
    <link>https://verynomagic.com/</link>
    <atom:link href="https://verynomagic.com/feed.xml" rel="self" type="application/rss+xml" />
    <pubDate>Thu, 22 Jun 2023 13:06:35 +0000</pubDate>
    <lastBuildDate>Thu, 22 Jun 2023 13:06:35 +0000</lastBuildDate>
    <generator>Jekyll v3.9.3</generator>
    
      <item>
        <title>Multiple DNS resolvers in OS X</title>
        <description>&lt;p&gt;Lately I’ve been trying out &lt;a href=&quot;https://consul.io&quot;&gt;consul&lt;/a&gt; and I love some of its core concepts. One of them is service discovery, which is provided through either an HTTP API or a DNS interface.&lt;/p&gt;

&lt;p&gt;The DNS interface works well, but it’s hard to try out on your own laptop. Sure, you can &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dig @&amp;lt;consul_server_ip&amp;gt; -p 8600&lt;/code&gt; but anything else turns out to be difficult.&lt;/p&gt;

&lt;p&gt;My first try was to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curl&lt;/code&gt;’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--dns-servers&lt;/code&gt; option. The documentation reads:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;--dns-servers &amp;lt;ip-address,ip-address&amp;gt;
       Set  the  list  of  DNS  servers to be used instead of the system
       default.  The list of IP addresses should be separated with commas. Port
       numbers may also optionally be given as :&amp;lt;port-number&amp;gt; after each IP
       address.

       This option requires that libcurl was built with a resolver backend that
       supports this operation. The c-ares backend is the only such one.
       (Added in 7.33.0)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Simple enough, right? (#1)&lt;/p&gt;

&lt;p&gt;Unfortunately, at the time of writing OS X’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curl&lt;/code&gt; isn’t compiled with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;c-ares&lt;/code&gt; resolver. So let’s compile our own &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curl&lt;/code&gt; to bake in the support needed:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ brew install curl --with-c-ares&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Simple enough, right? (#2)&lt;/p&gt;

&lt;p&gt;Unfortunately, curl times out using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--dns-servers &amp;lt;consul_server_ip&amp;gt;:8600&lt;/code&gt;. A quick &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tcpdump&lt;/code&gt; shows requests going out to DNS standard port 53, so something’s up.&lt;/p&gt;

&lt;p&gt;I had a quick look at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curl&lt;/code&gt;’s source code, following into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;c-ares&lt;/code&gt; source code and found &lt;a href=&quot;https://github.com/bagder/c-ares/blob/e3b04e5a4796215d2483aba3cb75c72ba337ac14/ares_set_servers_csv.3#L37&quot;&gt;this gem&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;The port option is currently ignored by c-ares internals
and the standard port is always used.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=4DuKPHXRLjA&quot;&gt;Aw, blërg&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;As usual with The Internets, someone else already had &lt;a href=&quot;https://github.com/bagder/c-ares/pull/19&quot;&gt;a solution for me&lt;/a&gt;, so I just had to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;brew edit curl&lt;/code&gt;, add the following patch and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;brew reinstall curl --with-c-ares&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-diff highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gh&quot;&gt;diff --git a/Library/Formula/c-ares.rb b/Library/Formula/c-ares.rb
index 960521c..366fa16 100644
&lt;/span&gt;&lt;span class=&quot;gd&quot;&gt;--- a/Library/Formula/c-ares.rb
&lt;/span&gt;&lt;span class=&quot;gi&quot;&gt;+++ b/Library/Formula/c-ares.rb
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;@@ -6,11 +6,9 @@&lt;/span&gt; class CAres &amp;lt; Formula
   url 'http://c-ares.haxx.se/download/c-ares-1.10.0.tar.gz'
   sha1 'e44e6575d5af99cb3a38461486e1ee8b49810eb5'

-  bottle do
&lt;span class=&quot;gd&quot;&gt;-    cellar :any
-    sha1 &quot;aa711a345bac4780f2e7737c212c1fb5f7862de8&quot; =&amp;gt; :yosemite
-    sha1 &quot;c6851c662552524fa92e341869a23ea72dbc4375&quot; =&amp;gt; :mavericks
-    sha1 &quot;27494a19ac612daedeb55356e911328771f94b19&quot; =&amp;gt; :mountain_lion
&lt;/span&gt;&lt;span class=&quot;gi&quot;&gt;+  patch do
+    url &quot;https://github.com/bagder/c-ares/pull/19.patch&quot;
+    sha256 &quot;99ef83d196fa550f2c46335abd63d825ba8650d686d7713e774579385d7c8998&quot;
&lt;/span&gt;   end

   def install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note: remember to rollback that change after compiling, so that you don’t get merge conflicts next time this formula is updated!&lt;/p&gt;

&lt;p&gt;(sidenote: how cool is GitHub?? Just adding a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.diff&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.patch&lt;/code&gt; gives you exactly what you want!)&lt;/p&gt;

&lt;p&gt;So, after all this work, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curl&lt;/code&gt; should work with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;consul&lt;/code&gt;’s DNS interface. But in practice, you just enabled &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curl&lt;/code&gt; to use alternate DNS servers, not your whole system. Wouldn’t it be great to use your browser to access a web server that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;consul&lt;/code&gt; knows about?&lt;/p&gt;

&lt;p&gt;This is usually where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/resolv.conf&lt;/code&gt; comes into play. Being OS X though, things aren’t as simple; as far as I could tell, half of the standard *nix CLI tools have this notice on their man pages:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Mac OS X NOTICE
       The host command does not use the host name and address resolution or
       the DNS query routing mechanisms used by other processes running on Mac
       OS X.  The results of name or address queries printed by host may differ
       from those found by other processes that use the Mac OS X native name
       and address resolution mechanisms.  The results of DNS queries may also
       differ from queries that use the Mac OS X DNS routing library.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Well, that sucks. But it got me curious as to what exactly is this “Mac OS X native name and address resolution mechanisms”.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;man 5 resolver&lt;/code&gt; is quite interesting in that regard. It suggests the possibility of different DNS configurations for specific domains, so I tried it
 by creating this file:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; /etc/resolver/dc1.consul
domain dc1.consul
port 8600
nameserver &amp;lt;consul_server_1&amp;gt;.8600
nameserver &amp;lt;consul_server_2&amp;gt;.8600
nameserver &amp;lt;consul_server_3&amp;gt;.8600
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Some of these configs are redundant, namely defining explicitly a domain when the file name should be enough and defining the port in every nameserver when the default port was changed before. This was made to make clear what should be happening here.&lt;/p&gt;

&lt;p&gt;Anyway, I also found out a nice little command that lets you check your current DNS configurations (which resolvers you have defined, in which order are they configured, which domains do they resolve): &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scutil --dns&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Assuming everything went ok, you should see your custom resolver there.&lt;/p&gt;

&lt;p&gt;Another way you can test this now is to run:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;dscacheutil &lt;span class=&quot;nt&quot;&gt;-q&lt;/span&gt; host &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; name webserver.service.dc1.consul
name: webserver.service.dc1.consul
ip_address: &amp;lt;webserver_ip_address&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In other news, you can now use Consul domains directly in your browsers! Sadly, none of the major browsers support &lt;a href=&quot;https://tools.ietf.org/html/rfc2782&quot;&gt;RFC 2782&lt;/a&gt; SRV lookups, so you’ll still have to add the port if your webserver is running on a non-standard port.&lt;/p&gt;
</description>
        <pubDate>Mon, 06 Jul 2015 23:41:00 +0000</pubDate>
        <link>https://verynomagic.com/2015/07/multiple-dns-resolvers-in-os-x.html</link>
        <guid isPermaLink="true">https://verynomagic.com/2015/07/multiple-dns-resolvers-in-os-x.html</guid>
        
        
      </item>
    
      <item>
        <title>Say 'No' to sshpass</title>
        <description>&lt;p&gt;&lt;em&gt;December 3, 2019: updated post to work on macOS 10.14&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I recently started fiddling with Ansible. I’m in a position where I see what all the fuss is about, but its quirks still nag me; one of which is the requirement to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sshpass&lt;/code&gt; for when you don’t have your SSH keys in place.&lt;/p&gt;

&lt;p&gt;I &lt;em&gt;really&lt;/em&gt; don’t like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sshpass&lt;/code&gt; - mostly because of security concerns - but the end goal of SSH automation is still worth pursuing, I think.&lt;/p&gt;

&lt;p&gt;So, this exercise started by being stubborn in believing you could mostly do what &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sshpass&lt;/code&gt; does with plain vanilla &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt;! In fact, I would argue that this might be A Better Way™, but you’re free to disagree. =)&lt;/p&gt;

&lt;p&gt;I want to store my passwords in an OS X keychain and have them read straight to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt;, so first we’ll create a secure keychain for this purpose:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# create a new keychain&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;security create-keychain &lt;span class=&quot;nt&quot;&gt;-P&lt;/span&gt; test.keychain
&lt;span class=&quot;c&quot;&gt;# have it lock on sleep or after 5min&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;security set-keychain-settings &lt;span class=&quot;nt&quot;&gt;-lu&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; 300 test.keychain
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;OS X command line tools for system management seem to be an after-thought, as I accidentally messed up my keychain search index while researching for this post and could only recover by using the GUI &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Keychain Access&lt;/code&gt; app (that might be a story for a later post).&lt;/p&gt;

&lt;p&gt;In any case, securely adding a new password to the keychain doesn’t seem possible through the CLI as the tool mandates inserting the password as a command line argument. The hack I came up with for not having the password stored in the clear on the shell history file was to write it elsewhere (anywhere you can type text), copying to the clipboard (I know, I know -_- ) and having the shell read from the clipboard:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;security add-generic-password &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &amp;lt;username&amp;gt; &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; ldap &lt;span class=&quot;nt&quot;&gt;-w&lt;/span&gt; &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;pbpaste&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
           test.keychain
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The other way you could go about it would be to use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Keychain Access&lt;/code&gt; app and create the password item there.&lt;/p&gt;

&lt;p&gt;Having done that, we now have to coerce &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt; to use the password in the keychain. This was a lot harder than I previously thought, as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt; tries &lt;strong&gt;very&lt;/strong&gt; hard to force you to type the password interactively, for security reasons. Having said that, here is what the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;man&lt;/code&gt; page states:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SSH_ASKPASS           If ssh needs a passphrase, it will read the passphrase
                      from the current terminal if it was run from a terminal.
                      If ssh does not have a terminal associated with it but
                      DISPLAY and SSH_ASKPASS are set, it will execute the
                      program specified by SSH_ASKPASS and open an X11 window
                      to read the passphrase. (...)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This means we can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSH_ASKPASS&lt;/code&gt; environment variable to pipe a password into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt;, as long as:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt; does not have a terminal associated with it;&lt;/li&gt;
  &lt;li&gt;there is a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DISPLAY&lt;/code&gt; environment variable set.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This was made so that X11 password prompts could be used with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt;. As we’re on OS X, this is kind of irrelevant.&lt;/p&gt;

&lt;p&gt;Oh well.&lt;/p&gt;

&lt;p&gt;The hard part here is tricking &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt; to run without an associated terminal and, after several failed attempts, I had to resort to The Internets. Luckily, I’m not the first person to have had this idea so &lt;a href=&quot;http://silmor.de/notty.php&quot;&gt;sample code was readily available&lt;/a&gt;. In fact, the linked post has almost everything you need to do &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt; automation; it just needed a little OS X love to work. I’ve set up a &lt;a href=&quot;https://github.com/pharaujo/notty&quot;&gt;github repository&lt;/a&gt; with the code so that this is easily reproduceable. You just need to clone the repo and follow the instructions to install &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;notty&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The fun part is that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSH_ASKPASS&lt;/code&gt; just needs to point to an executable that outputs the password to stdout. Of course that would be lame and terribly insecure, so we just need to write a script that, with your permission, grabs your password from the keychain.&lt;/p&gt;

&lt;p&gt;Place the following in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/bin/askpass&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;
/usr/bin/security find-generic-password &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &amp;lt;username&amp;gt; &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; ldap &lt;span class=&quot;nt&quot;&gt;-w&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                  test.keychain
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and make it executable:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;chmod &lt;/span&gt;u+x ~/bin/askpass
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The parameters you use here are the same you used when creating your generic-password item earlier.&lt;/p&gt;

&lt;p&gt;We now have the foundations to passwordless (sort of) &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt; and can try it with a server with password authentication:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ DISPLAY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;:99 &lt;span class=&quot;nv&quot;&gt;SSH_ASKPASS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;~/bin/askpass&quot;&lt;/span&gt; notty ssh &lt;span class=&quot;nt&quot;&gt;-q&lt;/span&gt; &amp;lt;server&amp;gt; &lt;span class=&quot;nb&quot;&gt;uptime&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If everything went well, a keychain prompt should appear asking for the keychain password. After that you’ll feel the sweet bliss of realizing you just had to type a password so that you don’t need to type another. ^_^’&lt;/p&gt;

&lt;p&gt;Most of the pieces are now in place to replace &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sshpass&lt;/code&gt; (that was the point of the exercise, remember?). As &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ansible&lt;/code&gt; is hard-coded to require &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sshpass&lt;/code&gt; for password-based authentication and to &lt;a href=&quot;https://github.com/ansible/ansible/blob/ce3ef7f4c16e47d5a0b5600e1c56c177b7c93f0d/lib/ansible/plugins/connections/ssh.py#L107&quot;&gt;disallow password authentication when not using -k&lt;/a&gt;, we need to fool it into using our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSH_ASKPASS&lt;/code&gt; setup.&lt;/p&gt;

&lt;p&gt;Our cool &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sshpass&lt;/code&gt; replacement (place it &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/local/bin/sshpass&lt;/code&gt;):&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;DISPLAY&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;:99
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;SSH_ASKPASS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$HOME&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/bin/askpass&quot;&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;[[&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;shift
&lt;/span&gt;notty &lt;span class=&quot;nv&quot;&gt;$@&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ansible&lt;/code&gt; uses the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-d&lt;/code&gt; flag to tell &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sshpass&lt;/code&gt; which file descriptor to read the password from. As we don’t care about that, we just ignore it and use the rest of the generated command directly.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; /tmp/a
server0[1:3]

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible &lt;span class=&quot;nt&quot;&gt;-i&lt;/span&gt; /tmp/a all &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; ping &lt;span class=&quot;nt&quot;&gt;-k&lt;/span&gt;
SSH password:
server01 | success &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;&quot;changed&quot;&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;,
    &lt;span class=&quot;s2&quot;&gt;&quot;ping&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;pong&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

server02 | success &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;&quot;changed&quot;&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;,
    &lt;span class=&quot;s2&quot;&gt;&quot;ping&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;pong&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

server03 | success &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;&quot;changed&quot;&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;,
    &lt;span class=&quot;s2&quot;&gt;&quot;ping&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;pong&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Success!&lt;/p&gt;

&lt;p&gt;This, of course, is not ideal as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ansible&lt;/code&gt; prompts you for a password anyway and then our replacement &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sshpass&lt;/code&gt; disregards that entirely. Fixing this requires patching &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lib/ansible/plugins/connections/ssh.py&lt;/code&gt;, which is a lot uglier than to type gibberish on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ansible&lt;/code&gt; prompt.&lt;/p&gt;

&lt;p&gt;And that concludes our exercise for now :)&lt;/p&gt;

&lt;p&gt;Thanks to &lt;a href=&quot;https://twitter.com/kintoandar&quot;&gt;@kintoandar&lt;/a&gt; for all the help with Ansible, and for pushing me to write this post!&lt;/p&gt;
</description>
        <pubDate>Tue, 16 Jun 2015 00:00:00 +0000</pubDate>
        <link>https://verynomagic.com/2015/06/say-no-to-sshpass.html</link>
        <guid isPermaLink="true">https://verynomagic.com/2015/06/say-no-to-sshpass.html</guid>
        
        
        <category>ssh</category>
        
        <category>sshpass</category>
        
        <category>ansible</category>
        
      </item>
    
  </channel>
</rss>
