Ansible doesn't see an installed Python module

后端 未结 1 562
粉色の甜心
粉色の甜心 2020-12-21 01:06

I am trying to create an Ansible playbook which would setup a local Postgres database to be used for local/dev testing of a certain app.

postgresql_db

相关标签:
1条回答
  • 2020-12-21 01:24

    This is caused by a well-known and described behaviour of Ansible.


    In short, if you specify localhost wherever in your inventory, Ansible will default to using /usr/bin/python for running the modules regardless of the connection: local setting.

    This in turn will cause problems if additional libraries were installed in a Python environment used to execute a playbook, but not for the /usr/bin/python.

    The solution is to specify ansible_python_interpreter for the localhost. In your case:

    [my_ws]
    localhost ansible_python_interpreter={{ansible_playbook_python}}
    

    Because of the above, the test to verify module presence should be:

    - command: "{{ ansible_python_interpreter | default('/usr/bin/python') }} -c 'import {{ module }}; print({{ module }}.__version__)'"
      vars:
        module: psycopg2
      register: test
    - debug:
        var: test.stdout
    
    0 讨论(0)
提交回复
热议问题