Ansible playbook, set environment variables not working
<p>I have to install psycopg to an old python (2.4). Everything works fine, except setting the environment variables -> LD_LIBRARY_PATH.</p>

<pre><code>- name: install psycopg
  shell: "{{ item }}"
    environment:
      CPPFLAGS: "-I/my_python/lib/python2.4/site-packages/mx/DateTime/mxDateTime"
      LD_LIBRARY_PATH: "/path_to_postgresql/lib"
  args:
    chdir: "/path_to_psycopg_src/"
  with_items:
    - ./configure --prefix=/my_python --with-python=/my_python/bin/python --with-postgres-libraries=/path_to_postgresql/lib --with-postgres-includes=/path_postgresql/include --with-mxdatetime-includes=/my_python/lib/python2.4/site-packages/mx/DateTime/mxDateTime
    - make
    - make install
</code></pre>

<p>After successfull installation I get the following error:</p>

<pre><code>&gt;&gt;&gt; import psycopg
    ImportError: libpq.so.4: cannot open shared object file: No such file or directory
</code></pre>

<p>When I export it manually, it works fine:</p>

<pre><code>export LD_LIBRARY_PATH="/path_postgresql/lib"
&gt;&gt;&gt; import psycopg
&gt;&gt;&gt; psycopg
&lt;module 'psycopg' from '/my_python/lib/python2.4/site-packages/psycopgmodule.so'&gt;
</code></pre>

<p>Because you set the <code>LD_LIBRARY_PATH</code> just for <code>install psycopg</code> task. If you want to set an environment variable not just for task/playbook I think you need to edit <code>/etc/environment</code></p>

python ansible ansible-playbook