{"id":1999,"date":"2017-08-31T10:45:52","date_gmt":"2017-08-31T15:45:52","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=1999"},"modified":"2017-08-31T10:45:52","modified_gmt":"2017-08-31T15:45:52","slug":"ansible-errno-2-no-such-file-or-directory","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2017\/08\/ansible-errno-2-no-such-file-or-directory\/","title":{"rendered":"Ansible: [Errno 2] No such file or directory"},"content":{"rendered":"<p>I tried running a command on several remote servers at once via Ansible:<\/p>\n<p><code>$ ansible -a 'rpcinfo -p' centos<\/code><\/p>\n<p>Which returned a series of errors:<\/p>\n<p><code>ariel.osric.net | FAILED | rc=2 &gt;&gt;<br \/>\n[Errno 2] No such file or directory<\/p>\n<p>caliban.osric.net | FAILED | rc=2 &gt;&gt;<br \/>\n[Errno 2] No such file or directory<\/p>\n<p>trinculo.osric.net | FAILED | rc=2 &gt;&gt;<br \/>\n[Errno 2] No such file or directory<\/code><\/p>\n<p>I also received an error when I tried running it via ssh:<\/p>\n<p><code>$ ssh ariel.osric.net 'rpcinfo -p'<br \/>\nbash: rpcinfo: command not found<\/code><\/p>\n<p>I can run it interactively on a specific host:<\/p>\n<p><code>$ ssh ariel.osric.net<br \/>\n$ rpcinfo -p<br \/>\n   program vers proto   port  service<br \/>\n    100000    4   tcp    111  portmapper<br \/>\n    100000    3   tcp    111  portmapper<br \/>\n    100000    2   tcp    111  portmapper<br \/>\n    100000    4   udp    111  portmapper<br \/>\n    100000    3   udp    111  portmapper<br \/>\n    100000    2   udp    111  portmapper<\/code><\/p>\n<p>The problem is that the user profile isn&#8217;t loaded when running via ansible or a non-interactive ssh session. <code>rpcinfo<\/code> isn&#8217;t found in the <code>PATH<\/code>. In the next step I identify the full path:<\/p>\n<p><code>$ ssh ariel.osric.net<br \/>\n$ whereis rpcinfo<br \/>\nrpcinfo: \/usr\/sbin\/rpcinfo \/usr\/share\/man\/man8\/rpcinfo.8.gz<\/code><\/p>\n<p>(<code>\/usr\/sbin<\/code> is added to the path via <code>\/etc\/profile<\/code>)<\/p>\n<p>Once I specified the full path, it worked:<\/p>\n<p><code>$ ansible -a '\/usr\/sbin\/rpcinfo -p' centos<\/p>\n<p>ariel.osric.net | SUCCESS | rc=0 &gt;&gt;<br \/>\n   program vers proto   port  service<br \/>\n    100000    4   tcp    111  portmapper<br \/>\n    100000    3   tcp    111  portmapper<br \/>\n    100000    2   tcp    111  portmapper<br \/>\n    100000    4   udp    111  portmapper<br \/>\n    100000    3   udp    111  portmapper<br \/>\n    100000    2   udp    111  portmapper<\/code><\/p>\n<p>Etc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If a command run via ansible returns &#8220;[Errno 2] No such file or directory&#8221; it likely means you need to specify the full path to the command.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[439],"tags":[423],"class_list":["post-1999","post","type-post","status-publish","format-standard","hentry","category-ansible","tag-ansible"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1999","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=1999"}],"version-history":[{"count":3,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1999\/revisions"}],"predecessor-version":[{"id":2002,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/1999\/revisions\/2002"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=1999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=1999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=1999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}