title: $PATH environment variable in Ansible provisioner for Vagrant
body: <p>When working with Ansible as a provisioner for Vagrant, variables that I define in <code>/etc/environment</code> are not being picked up. I can't find the documentation that says how vagrant builds it's environment variables.</p>
  
  <p>Which file should I modify so that updates to the <code>PATH</code> environment are picked up by the Ansible provisioner?</p>
  
  <pre><code>// In my foo role/task...
  
  - name: check path
    command: msg="{{ print $PATH }}"
  </code></pre>
  
  <p>Results in</p>
  
  <pre><code>/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  </code></pre>
  
  <p>I want to modify my <code>$PATH</code> so that it is available both to the Ansible provisioner and the users when they log into my Vagrant box.</p>
  
  <p>Relevant questions:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/21422158/ansible-accessing-local-environment-variables">Ansible - accessing local environment variables</a></li>
  </ul>
  
  <p><strong>Current /etc/environment configuration:</strong></p>
  
  <pre><code>vagrant@localhost:~$ cat /etc/environment 
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/bin/composer:/home/vagrant/.composer/vendor/bin"
  </code></pre>
  
  <p><strong>Contents of <code>roles/ansible_dev</code>:</strong></p>
  
  <pre><code>- name: check path
    shell: echo $PATH
    register: PATH
  - debug: var=PATH
  # outputs /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  
  - name: update path
    shell: source /etc/environment;export PATH
  
  # outputs the same, note my .composer directory still missing at the end
  - name: check path AGAIN
    command: echo $PATH
    register: PATH2
  - debug: var=PATH2
  </code></pre>
  
  <p><strong>Testing</strong></p>
  
  <p>After <code>vagrant up</code> I am doing <code>vagrant provision --provision-with=ansible</code> for testing.</p>
  
  <pre><code>TASK: [ansible_dev | check path] ********************************************** 
  changed: [localhost]
  
  TASK: [ansible_dev | debug var=PATH] ****************************************** 
  ok: [localhost] =&gt; {
      "PATH": {
          "changed": true, 
          "cmd": "echo $PATH", 
          "delta": "0:00:00.002239", 
          "end": "2014-10-15 03:04:34.604944", 
          "invocation": {
              "module_args": "echo $PATH", 
              "module_name": "shell"
          }, 
          "rc": 0, 
          "start": "2014-10-15 03:04:34.602705", 
          "stderr": "", 
          "stdout": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", 
          "stdout_lines": [
              "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
          ]
      }
  }
  
  TASK: [ansible_dev | update path] ********************************************* 
  changed: [localhost]
  
  TASK: [ansible_dev | check path AGAIN] **************************************** 
  changed: [localhost]
  
  TASK: [ansible_dev | debug var=PATH2] ***************************************** 
  ok: [localhost] =&gt; {
      "PATH2": {
          "changed": true, 
          "cmd": [
              "echo", 
              "$PATH"
          ], 
          "delta": "0:00:00.003051", 
          "end": "2014-10-15 03:04:34.814571", 
          "invocation": {
              "module_args": "echo $PATH", 
              "module_name": "command"
          }, 
          "rc": 0, 
          "start": "2014-10-15 03:04:34.811520", 
          "stderr": "", 
          "stdout": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", 
          "stdout_lines": [
              "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
          ]
      }
  }
  </code></pre>