Ansible 剧本,设置环境变量不起作用
Ansible playbook, set environment variables not working
我必须将 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'>
因为您设置 LD_LIBRARY_PATH
只是为了 install psycopg
任务。如果你想设置一个环境变量而不仅仅是 task/playbook 我认为你需要编辑 /etc/environment
我必须将 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'>
因为您设置 LD_LIBRARY_PATH
只是为了 install psycopg
任务。如果你想设置一个环境变量而不仅仅是 task/playbook 我认为你需要编辑 /etc/environment