Ansible python interpreter

Hi. You can fix it by installing the “required python packages” in your venv with pip.

---
- name: Install SQL scripts on Private PostgreSQL Instance
  hosts: localhost
  gather_facts: true
  become: true

  tasks:
    - name: Install required python packages
      ansible.builtin.pip:
       name:
         - libpq-dev
         - python3-psycopg2
       virtualenv: "{{ ansible_facts['env']['VIRTUAL_ENV'] }}"
       state: present

The other option is to set the python interpreter to your OS python interpreter, as pointed out by @felixfontein:

---
- name: Install SQL scripts on Private PostgreSQL Instance
  hosts: localhost
  gather_facts: false
  become: true
  vars:
     ansible_python_interpreter: "/usr/bin/python3"