title: Ansible: How to globally set PATH for solaris
body: <p>I am writing Ansible playbooks to setup and install our applications on Solaris servers.</p>
  
  <p>The problem is that the (bash) scripts which I need to execute all assume that a certain directory lies on the PATH, namely <code>/data/bin</code> - which would normally not be a problem were it not for Ansible ignoring all the <code>.profile</code> and <code>.bashrc</code> config.</p>
  
  <p>Now, I know that you can specify the environment for <code>shell</code> tasks via the <code>environment</code> flag, for example like this:</p>
  
  <pre><code>- shell: printenv
    environment:
      PATH: /usr/bin:/usr/sbin:/data/bin
  </code></pre>
  
  <p>This will properly path the <code>/data/bin</code> folder, and the <code>printenv</code> command will correctly display (or my bash scripts would correctly run).</p>
  
  <p><strong>But.</strong> There are two problems however:</p>
  
  <ul>
  <li>First of all it is very annoying to have to specify the environment over and over again. I know that you can define the environment in some playbook base file variable and the reference that, but you <em>still</em> have to set <code>environment: ...</code> on every single <code>shell</code> task.</li>
  <li>Secondly, the above example does not allow me to specify the path dynamically, e.g. as <code>PATH: $PATH:/data/bin</code> - because Ansible executes this in a way which does not resolve <code>$PATH</code>, thus the command fails catastrophically. So essentially this will override any other changes to <code>PATH</code>.</li>
  </ul>
  
  <p>I am looking for a solution where</p>
  
  <ul>
  <li>the additional <code>PATH</code> entry should only be added <strong>once</strong></li>
  <li>the additional <code>PATH</code> entry should not override entries added by other tasks</li>
  </ul>
  
  <p>P.S. I found this nice explanation on <a href="https://coderwall.com/p/ynvi0q/updating-path-with-ansible-system-wide" rel="nofollow">how to do this on Linux</a>, but it makes use of <code>/etc/environment</code> which does not exist on Solaris. (And <code>/etc/profile</code> is once again ignored by Ansible.)</p>