Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

PGSQL provisioning fails: wrong python interpreter and no database #2024

Closed
JASUMAHIRO opened this issue Mar 19, 2020 · 8 comments
Closed

PGSQL provisioning fails: wrong python interpreter and no database #2024

JASUMAHIRO opened this issue Mar 19, 2020 · 8 comments

Comments

@JASUMAHIRO
Copy link

Issue Type

  • Bug Report / Support Request

Your Environment

$ vagrant --version && echo "VirtualBox `vboxmanage --version`" && ansible --version
Vagrant 2.2.4
VirtualBox 5.2.34_Ubuntur133883
ansible 2.5.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/jake/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.17 (default, Nov  7 2019, 10:07:09) [GCC 7.4.0]

Your OS

  • Linux (version)

Full console output

https://gist.github.com/JASUMAHIRO/0a5e34f8e11e7ccb1bb0e641ad7eee5b

Summary

Using PostgreSQL is impossible. It should be matter of changing one variable value from config.yml as per latest documentation but it fails.

At first it fails with python-psycopg2 which it can't find since it is using Python (2). I was able to solve this by prepending ansible_python_interpreter=/usr/bin/python3 to provisioning/roles/geerlingguy.php-pgsql/molecule/default/playbook.yml

However, after this vagrant provision returns a new error also related to PGSQL in which it claims that database cannot be found and therefore connected.

I'm using latest repo from git.

@geerlingguy
Copy link
Owner

@JASUMAHIRO - Are you trying to run one playbook by itself? (the provisioning/roles/geerlingguy.php-pgsql/molecule/default/playbook.yml playbook)? Doing that is not supported, just vagrant up and other vagrant-related commands. The Molecule playbooks don't necessarily work directly against a Drupal VM instance—they're used for internal testing in CI for the roles themselves.

@geerlingguy
Copy link
Owner

Also if you're on Ubuntu 18.04, it should automatically set the postgresql_python_library to python3-psycopg2.

See: https://github.com/geerlingguy/ansible-role-postgresql/blob/1d5370646cb46a33b0724fdf031d9835c49521d2/vars/Ubuntu-18.yml#L11

Can you supply your config.yml?

@JASUMAHIRO
Copy link
Author

Hi @geerlingguy

No, I've been using only vagrant up and vagrant provision. The mentioned playbook was just additional information to clarify that how the initial psycopg2 problem was solved.

I'll post the config file but it is pretty much like the original except for the Drupal db backend and major version. And for other files I've just modified no_log:true to no_log:false.

@JASUMAHIRO
Copy link
Author

I tried again with vanilla git clone and changed only mysql to pgsql. This time I connected to VM with SSH and installed sudo apt install python-psycopg2 since error generated by vagrant up clearly states that it is trying to use Python2 and not Python 3 for which psycopg2 was already installed in VM. (Also tried to add python-psycopg2 to config.yml extra packages but it didn't get installed)

TASK [geerlingguy.postgresql : Ensure PostgreSQL users are present.] ***********
[WARNING]: Module did not set no_log for no_password_changes
failed: [drupalvm] (item={u'password': u'drupal', u'db': u'drupal', u'name': u'drupal', u'priv': u'ALL'}) => {"ansible_loop_var": "item", "changed": false, "item": {"db": "drupal", "name": "drupal", "password": "drupal", "priv": "ALL"}, "msg": "Failed to import the required Python library (psycopg2) on ********vm's Python /usr/bin/python. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"}

However, as the issue itself describes, this will fix the first error but ends up in db connection problem due to non-existent database.

TASK [geerlingguy.postgresql : Ensure PostgreSQL users are present.] ***********
[WARNING]: Module did not set no_log for no_password_changes
failed: [drupalvm] (item={u'password': u'drupal', u'db': u'drupal', u'name': u'drupal', u'priv': u'ALL'}) => {"ansible_loop_var": "item", "changed": false, "item": {"db": "drupal", "name": "drupal", "password": "drupal", "priv": "ALL"}, "msg": "unable to connect to database: FATAL:  database \"********\" does not exist\n"}

Is this working for someone?

@geerlingguy
Copy link
Owner

@JASUMAHIRO - This is likely due to this change: geerlingguy/ansible-role-postgresql#31 — which was merged a few months ago. It didn't hit a major Drupal VM release until recently, so you're probably the first to update/try a new version and stumble into it.

I'll boot up an instance locally and see what needs to change—probably just the owner reference on the database (and remove the database reference on the user) since they switched setup order.

@geerlingguy
Copy link
Owner

I'm also planning on fixing the Python2/Python3 issue by forcing Drupal VM to use the /usr/bin/python3 interpreter. Hopefully it doesn't break anything else, but I've been testing most of my roles on Python 3 now anyways, so it shouldn't, at least.

@geerlingguy
Copy link
Owner

See commit here: 59f28f2

The basic changes required for now if you want to use older versions of Drupal VM (which will be the defaults in the next version of Drupal VM and should work with the docs again):

  1. Add ansible_python_interpreter: /usr/bin/python3 to your config.yml
  2. Remove db and priv keys from your postgresql_users variable items.
  3. Add owner: "{{ drupal_db_user }}" to your postgresql_databases variable items.

The above changes won't be necessary once 5.2.0 is released (should be today, hopefully!).

@JASUMAHIRO
Copy link
Author

Hi

I just cloned the repo and while the provisioning went through I can't access database i.e. Adminer won't connect (PGSQL nor MySQL). However, the Drupal site is responding so there must a database.

Should the dashboard state implicitly that which database is in use? Now it says MySQL.

But for now I think that it is better to just install pgsql etc. locally and keep developing without this VM since it seems to take a lot of time to get up and running.

kentr added a commit to kentr/drupal-vm that referenced this issue Apr 4, 2020
* tag '5.2.0': (80 commits)
  Issue geerlingguy#2025: Update Changelog for 5.2.0 release.
  Issue geerlingguy#2025: Mention new var to override for older linux versions.
  Issue geerlingguy#1675: Use custom drush bin.
  Issue geerlingguy#1675: Test postgresql configuration again.
  Fixed structure for python interpreter override.
  Finally get some python sanity.
  Pesky quoting.
  Pesky semicolons.
  More test follow-ups for python interpreter.
  Issue geerlingguy#2024 extra test fixes.
  Follow-up to geerlingguy#2024: Fix failing tests due to python interpreter.
  Fixes geerlingguy#2024: Fix chicken-and-egg ordering of postgresql database and user.
  Issue geerlingguy#2024: Update postgresql role to latest version.
  Update mysql role to latest version.
  Update php role to latest version.
  Fixes geerlingguy#1960: Use newer Solr version and make sure correct Java package is installed.
  Fix docs for composer-dependency use concerning drupal_enable_modules.
  Update php role to latest version.
  Update php role to latest version.
  Add probot/stale configuration.
  ...
kentr added a commit to kentr/drupal-vm that referenced this issue Apr 12, 2020
* merge-upstream: (82 commits)
  Use `auto_legacy` for `ansible_python_interpreter`
  Use `/usr/bin/python` for `ansible_python_interpreter`
  Issue geerlingguy#2025: Update Changelog for 5.2.0 release.
  Issue geerlingguy#2025: Mention new var to override for older linux versions.
  Issue geerlingguy#1675: Use custom drush bin.
  Issue geerlingguy#1675: Test postgresql configuration again.
  Fixed structure for python interpreter override.
  Finally get some python sanity.
  Pesky quoting.
  Pesky semicolons.
  More test follow-ups for python interpreter.
  Issue geerlingguy#2024 extra test fixes.
  Follow-up to geerlingguy#2024: Fix failing tests due to python interpreter.
  Fixes geerlingguy#2024: Fix chicken-and-egg ordering of postgresql database and user.
  Issue geerlingguy#2024: Update postgresql role to latest version.
  Update mysql role to latest version.
  Update php role to latest version.
  Fixes geerlingguy#1960: Use newer Solr version and make sure correct Java package is installed.
  Fix docs for composer-dependency use concerning drupal_enable_modules.
  Update php role to latest version.
  ...
kentr added a commit to kentr/drupal-vm that referenced this issue Apr 15, 2020
* merge-upstream: (82 commits)
  Use `auto_legacy` for `ansible_python_interpreter`
  Use `/usr/bin/python` for `ansible_python_interpreter`
  Issue geerlingguy#2025: Update Changelog for 5.2.0 release.
  Issue geerlingguy#2025: Mention new var to override for older linux versions.
  Issue geerlingguy#1675: Use custom drush bin.
  Issue geerlingguy#1675: Test postgresql configuration again.
  Fixed structure for python interpreter override.
  Finally get some python sanity.
  Pesky quoting.
  Pesky semicolons.
  More test follow-ups for python interpreter.
  Issue geerlingguy#2024 extra test fixes.
  Follow-up to geerlingguy#2024: Fix failing tests due to python interpreter.
  Fixes geerlingguy#2024: Fix chicken-and-egg ordering of postgresql database and user.
  Issue geerlingguy#2024: Update postgresql role to latest version.
  Update mysql role to latest version.
  Update php role to latest version.
  Fixes geerlingguy#1960: Use newer Solr version and make sure correct Java package is installed.
  Fix docs for composer-dependency use concerning drupal_enable_modules.
  Update php role to latest version.
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants