简体   繁体   中英

Ansible playbook, set environment variables not working

I have to install psycopg to an old python (2.4). Everything works fine, except setting the environment variables -> LD_LIBRARY_PATH.

- 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

After successfull installation I get the following error:

>>> import psycopg
    ImportError: libpq.so.4: cannot open shared object file: No such file or directory

When I export it manually, it works fine:

export LD_LIBRARY_PATH="/path_postgresql/lib"
>>> import psycopg
>>> psycopg
<module 'psycopg' from '/my_python/lib/python2.4/site-packages/psycopgmodule.so'>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM