{"id":7829,"date":"2015-10-30T08:06:45","date_gmt":"2015-10-30T08:06:45","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/10\/30\/not-possible-to-source-bashrc-with-ansible-open-source-projects-ansible-ansible\/"},"modified":"2015-10-30T08:06:45","modified_gmt":"2015-10-30T08:06:45","slug":"not-possible-to-source-bashrc-with-ansible-open-source-projects-ansible-ansible","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/10\/30\/not-possible-to-source-bashrc-with-ansible-open-source-projects-ansible-ansible\/","title":{"rendered":"Not possible to source .bashrc with Ansible-open source projects ansible\/ansible"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/b483dea19c00b3d952f4958d67ea4bd1?s=128&amp;d=identicon&amp;r=PG\" \/> <strong>Steve Midgley<\/strong><\/p>\n<p>You have two options to use source with ansible. One is with the &#8220;shell:&#8221; command and \/bin\/sh (the ansible default). &#8220;source&#8221; is called &#8220;.&#8221; in \/bin\/sh. So your command would be:<\/p>\n<pre><code>- name: source bashrc\n  sudo: no   \n  shell: . \/home\/username\/.bashrc &amp;&amp; [the actual command you want run]\n<\/code><\/pre>\n<p>Note you have to run a command after sourcing .bashrc b\/c each ssh session is distinct &#8211; every ansible command runs in a separate ssh transaction.<\/p>\n<p>Your second option is to force Ansible shell to use bash and then you can use the &#8220;source&#8221; command:<\/p>\n<pre><code>- name: source bashrc\n  sudo: no   \n  shell: source \/home\/username\/.bashrc &amp;&amp; [the actual command you want run]\n  args:\n     executable: \/bin\/bash\n<\/code><\/pre>\n<p>Finally, I&#8217;ll note that you may want to actually source &#8220;\/etc\/profile&#8221; if you&#8217;re on Ubuntu or similar, which more completely simulates a local login.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Steve Midgley You have two options to use source with ansible. One is with the &#8220;shell:&#8221; command and \/bin\/sh (the ansible default). &#8220;source&#8221; is called &#8220;.&#8221; in \/bin\/sh. So your command would be: &#8211; name: source bashrc sudo: no shell: . \/home\/username\/.bashrc &amp;&amp; [the actual command you want run] Note you have to run a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7829","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7829"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7829\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}