Ansible playbook,设置环境变量不起作用

时间:2016-09-09 06:50:30

标签: python ansible ansible-playbook

我必须将psycopg安装到旧的python(2.4)。一切正常,除了设置环境变量 - > 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

成功安装后,我收到以下错误:

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

当我手动导出时,它可以正常工作:

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

1 个答案:

答案 0 :(得分:1)

因为您只为LD_LIBRARY_PATH任务设置了install psycopg。如果你想设置一个环境变量,不仅仅是为了任务/剧本,我想你需要编辑/etc/environment