ANXS / postgresql

Fairly full featured Ansible role for Postgresql.
http://anxs.io/
MIT License
848 stars 573 forks source link

No package matching 'python-psycopg2' is available #523

Closed dmitvitalii closed 2 years ago

dmitvitalii commented 2 years ago

Facing the error on Ubuntu 20.04

TASK [ANXS.postgresql : PostgreSQL | Make sure the dependencies are installed | apt] ***********************************************
fatal: [${host_ip}]: FAILED! => {"changed": false, "msg": "No package matching 'python-psycopg2' is available"}

I tried to install psycopg2-binary and psycopg2 using pre_tasks, but none of them work.

pre_tasks:
  - block:
    - name: Install dependencies
      apt: 
        name: ["python3-pip", "libpq-dev"]
      become: yes
    - name: Install psycopg2
      pip: name=psycopg2
      become: yes

Full traceback

The full traceback is:
  File "/tmp/ansible_apt_payload_1xrddk9e/ansible_apt_payload.zip/ansible/modules/apt.py", line 478, in package_status
  File "/usr/lib/python3/dist-packages/apt/cache.py", line 305, in __getitem__
    raise KeyError('The cache has no package named %r' % key)
fatal: [${host_ip}]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "allow_unauthenticated": false,
            "autoclean": false,
            "autoremove": false,
            "cache_valid_time": 3600,
            "deb": null,
            "default_release": null,
            "dpkg_options": "force-confdef,force-confold",
            "fail_on_autoremove": false,
            "force": false,
            "force_apt_get": false,
            "install_recommends": null,
            "only_upgrade": false,
            "package": [
                "python-psycopg2",
                "python-pycurl",
                "locales"
            ],
            "pkg": [
                "python-psycopg2",
                "python-pycurl",
                "locales"
            ],
            "policy_rc_d": null,
            "purge": false,
            "state": "present",
            "update_cache": true,
            "update_cache_retries": 5,
            "update_cache_retry_max_delay": 12,
            "upgrade": null
        }
    },
    "msg": "No package matching 'python-psycopg2' is available"
}

Installing "python3-psycopg2" didn't help either

dmitvitalii commented 2 years ago

Found a workaround:

tasks:
  - block:
        # ...
        vars:
            postgresql_apt_py2_dependencies: []

But it looks like it shouldn't be searching for py2 dependencies on Ubuntu 20.04 at all

jpeyret commented 2 years ago

@dmitvitalii

Had the same problem, also on Ubuntu 20.04, but you don't have to modify the code.

postgresql_apt_py3_dependencies: ["python3-psycopg2", "locales"]
postgresql_apt_py2_dependencies: ["python-psycopg2", "python-pycurl", "locales"]
postgresql_apt_dependencies: "{{ postgresql_apt_py3_dependencies if 👉'python3'👈 in  ansible_python_interpreter|default('') else postgresql_apt_py2_dependencies }}"

So it appears you just need to tell ANXS.postgresql that it is dealing with python 3 and will pick the python3 dependencies, not python2's.

Now, ansible_python_interpreter appears quite a bit in the yamls but I figured all I needed to do was to have python3 in it for this role.

    - role: ANXS.postgresql
      become: yes

      vars:
        #try to convince not to look for python 2 stuff...
        #👇 (that's the python on my Ubuntu VM)
        ansible_python_interpreter: "/usr/bin/python3" 

and it worked.

btw, if your v3 python is not named python3, but just plain python, I'd first try to put in a bogus python3 name, in case it doesn't need it for anything else. Or I'd symlink python -> python3 and use that.

maglub commented 2 years ago

This is more a support case than a bug request.

By ensuring you use python3, you get rid of it. On those environments, you should use python3 anyways.

aehlke commented 2 years ago

It's a bug request because it misidentifies what is python3

MVKozlov commented 1 year ago

this is a bug dependencies line line shoud be

postgresql_apt_dependencies: "{{ postgresql_apt_py3_dependencies if ansible_python.version.major == 3 else postgresql_apt_py2_dependencies }}"

this way it's independent of ansible_python_interpreter