From bc4508ffc339e00983ffdb435cd07433f045628b Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 6 Oct 2020 09:19:46 +0100 Subject: [PATCH 1/6] Update ofn-install to work with Ubuntu 20 --- roles/compatibility/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/compatibility/tasks/main.yml b/roles/compatibility/tasks/main.yml index af3a30c28..72604f495 100644 --- a/roles/compatibility/tasks/main.yml +++ b/roles/compatibility/tasks/main.yml @@ -16,4 +16,4 @@ vars: bionic_packages: - software-properties-common - when: ansible_distribution_major_version == '18' + when: ansible_distribution_major_version >= '18' From fe3dfe37f81367836252e7e26d1183094a5831f1 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Tue, 14 Jun 2022 23:15:51 -0300 Subject: [PATCH 2/6] Use Python 3 in Ubuntu 20 and onwards Starting in version 20 Python 2 packages, specially python-psycopg2 required by geerlingguy.postgresql, are no longer part of the distro and we have to work with their versions for Python 3. My first attempt to get this done was by setting the `ansible_python_interpreter` to something like: ``` ansible_python_interpreter: "/usr/bin/python{% if ansible_distribution_major_version < '20' %}2.7{% else %}3{% endif%}" ``` But it dind't work because at the time `ansible_python_interpreter` needs to be evaluated `ansible_distribution_major_version` still is undefined. This is the reason I'm going for this particular more creative solution. In the future, when the project maintainers decide to end support for Ubuntu 16, this solution should not be necessary and we can just work with Python 3 in Ubuntu 18 and 20. --- inventory/group_vars/all.yml | 4 ++-- playbooks/setup.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/inventory/group_vars/all.yml b/inventory/group_vars/all.yml index d0987c049..60cd70fa7 100644 --- a/inventory/group_vars/all.yml +++ b/inventory/group_vars/all.yml @@ -395,8 +395,8 @@ nginx_configs: upstream: - upstream rails { server unix:{{ puma_sock }} fail_timeout=0; } -# Use python2.7 interpeter -ansible_python_interpreter: '/usr/bin/python2.7' +# Set python interpeter to the symlink created by setup +ansible_python_interpreter: '/usr/bin/python' # Fix for renamed branch in rbenv-install repo rbenv_plugins: diff --git a/playbooks/setup.yml b/playbooks/setup.yml index 6580347dc..6de106c3f 100644 --- a/playbooks/setup.yml +++ b/playbooks/setup.yml @@ -11,9 +11,9 @@ gather_facts: no remote_user: root tasks: - - name: Install python 2.7 + - name: Install python become: yes - raw: apt-get update -qq && apt-get install -qq python2.7 + raw: test $(lsb_release -sr | cut -d . -f1) -lt 20 && (apt-get update -qq && apt-get install -qq python2.7 && ln -s /usr/bin/python2.7 /usr/bin/python) || (apt-get update -qq && apt-get install -qq python3 && ln -s /usr/bin/python3 /usr/bin/python) tags: skip_ansible_lint # Add the default user and ssh keys as root From a8eb87f54dc184d0d749ce542d3426a66ff8afa3 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Tue, 14 Jun 2022 14:52:32 -0300 Subject: [PATCH 3/6] Do not install python-psycopg2 in Ubuntu 20 or newer This package no longer exists and was causing the following error: ``` TASK [common : install base packages] ********************************************************************************************************************************************* fatal: [local_vagrant]: FAILED! => {"changed": false, "msg": "No package matching 'python-psycopg2' is available"} Tuesday 14 June 2022 14:31:23 -0300 (0:00:00.361) 0:00:12.428 ********** ``` --- roles/common/tasks/main.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index efd20bf28..c891cb8ae 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -15,7 +15,6 @@ packages: # Ansible support - python-pycurl - - python-psycopg2 - python3-psycopg2 # unknown why or if needed @@ -44,6 +43,17 @@ - webp tags: packages +- name: install base packages for old distros + apt: + name: "{{ packages }}" + become: yes + vars: + packages: + # Ansible support + - python-psycopg2 + tags: packages + when: ansible_distribution_major_version <= '18' + - name: set up redis include_tasks: redis.yml From 7686a78c8f71697ca7765caf8695e57823081c1c Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Tue, 14 Jun 2022 17:46:43 -0300 Subject: [PATCH 4/6] Upgrade geerlingguy.postgresql ansible galaxy module This version adds support to Ubuntu 20 while still supports 16 and 18. Fixes the following error present when running in Ubuntu 20: ``` TASK [geerlingguy.postgresql : Include OS-specific variables (Debian).] *********************************************************************************************************** fatal: [local_vagrant]: FAILED! => {"ansible_facts": {}, "ansible_included_var_files": [], "changed": false, "message": "Could not find or access 'Ubuntu-20.yml'\nSearched in:\n\t/home/manzo/workspace/Camar inhaManzo/ofn-install/community/geerlingguy.postgresql/vars/Ubuntu-20.yml\n\t/home/manzo/workspace/CamarinhaManzo/ofn-install/community/geerlingguy.postgresql/Ubuntu-20.yml\n\t/home/manzo/workspace/Camarinh aManzo/ofn-install/roles/dbserver/vars/Ubuntu-20.yml\n\t/home/manzo/workspace/CamarinhaManzo/ofn-install/roles/dbserver/Ubuntu-20.yml\n\t/home/manzo/workspace/CamarinhaManzo/ofn-install/community/geerlinggu y.postgresql/tasks/vars/Ubuntu-20.yml\n\t/home/manzo/workspace/CamarinhaManzo/ofn-install/community/geerlingguy.postgresql/tasks/Ubuntu-20.yml\n\t/home/manzo/workspace/CamarinhaManzo/ofn-install/playbooks/v ars/Ubuntu-20.yml\n\t/home/manzo/workspace/CamarinhaManzo/ofn-install/playbooks/Ubuntu-20.yml on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote _src option"} Tuesday 14 June 2022 14:51:16 -0300 (0:00:00.015) 0:08:08.065 ********** ``` --- bin/requirements.yml | 2 +- inventory/group_vars/all.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/requirements.yml b/bin/requirements.yml index afb98f21d..1a12b2201 100644 --- a/bin/requirements.yml +++ b/bin/requirements.yml @@ -21,7 +21,7 @@ version: 3.1.0 - src: geerlingguy.postgresql - version: 1.4.5 + version: 3.3.0 - src: libre_ops.wal2json version: 1.0.5 diff --git a/inventory/group_vars/all.yml b/inventory/group_vars/all.yml index 60cd70fa7..90a443ec8 100644 --- a/inventory/group_vars/all.yml +++ b/inventory/group_vars/all.yml @@ -98,7 +98,7 @@ postgres_encoding: en_US.utf8 # Entries marked custom_* can be defined in /host_vars files, and will be appended # to the defaults if present. Make sure you use the "list" notation with the dashes! -postgresql_version: "{% if ansible_distribution_major_version == '16' %}9.5{% else %}10{% endif %}" +postgresql_version: "{% if ansible_distribution_major_version == '16' %}9.5{% elif ansible_distribution_major_version == '18' %}10{% else %}12{% endif %}" postgresql_data_dir: "/var/lib/postgresql/{{ postgresql_version }}/main" postgresql_bin_path: "/usr/lib/postgresql/{{ postgresql_version }}/bin" postgresql_config_path: "/etc/postgresql/{{ postgresql_version }}/main" From 349dd6a4e09a0ef5ccbc5913f45dc109b7ac5402 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Wed, 15 Jun 2022 18:30:53 -0300 Subject: [PATCH 5/6] Fix Ruby memory error in Ubuntu 20 In Ubuntu 20, when running assets precompilation there was this error: ``` TASK [deploy : precompile assets] ************************************************************************************************************************************************* fatal: [local_vagrant]: FAILED! => {"changed": true, "cmd": ["bash", "-lc", "bundle exec rake assets:precompile RAILS_ENV=development"], "delta": "0:00:05.815405", "end": "2022-06 -15 11:15:39.701298", "msg": "non-zero return code", "rc": -6, "start": "2022-06-15 11:15:33.885893", "stderr": "I, [2022-06-15T11:15:39.534899 #62413] INFO -- : Writing /home/op enfoodnetwork/apps/openfoodnetwork/releases-old/2022-06-15-111445/public/assets/iehack-725caee6a64e094fd6f6faeb3b7d8456ba36bfca88b2b2d46fd02661da15f6d7.js\nI, [2022-06-15T11:15:39 .535309 #62413] INFO -- : Writing /home/openfoodnetwork/apps/openfoodnetwork/releases-old/2022-06-15-111445/public/assets/iehack-725caee6a64e094fd6f6faeb3b7d8456ba36bfca88b2b2d46 fd02661da15f6d7.js.gz\nfree(): invalid pointer", "stderr_lines": ["I, [2022-06-15T11:15:39.534899 #62413] INFO -- : Writing /home/openfoodnetwork/apps/openfoodnetwork/releases-ol d/2022-06-15-111445/public/assets/iehack-725caee6a64e094fd6f6faeb3b7d8456ba36bfca88b2b2d46fd02661da15f6d7.js", "I, [2022-06-15T11:15:39.535309 #62413] INFO -- : Writing /home/ope nfoodnetwork/apps/openfoodnetwork/releases-old/2022-06-15-111445/public/assets/iehack-725caee6a64e094fd6f6faeb3b7d8456ba36bfca88b2b2d46fd02661da15f6d7.js.gz", "free(): invalid poi nter"], "stdout": "yarn install v1.22.4\n[1/4] Resolving packages...\nsuccess Already up-to-date.\nDone in 0.66s.", "stdout_lines": ["yarn install v1.22.4", "[1/4] Resolving packa ges...", "success Already up-to-date.", "Done in 0.66s."]} Wednesday 15 June 2022 08:15:39 -0300 (0:00:05.946) 0:00:55.217 ******** ``` The important part is: `free(): invalid pointer`. This is a kind of a generic memory error that I could not find the actual cause not even with valgrind. This led me to trial and error. First I investigated if removing from Gemfile some gems with native compilation such as `pg` and `json` had any effect, but the error persisted after all my tries. After that I went to remove all gems and reinstall and the error persisted. Then I tried to remove the Ruby being used and reinstall it. Which fixed the problem! But I must admit this is an ugly solution. Now knowing the error source is within the Ruby installation, I've tried to upgrade the `zzet.rbenv` ansible galaxy module, but had no success. I've also tried to remove jemalloc from the installation and the error persisted. Finally I have moved the uninstall/reinstall to being the very next thing after calling `zzet.rbenv` and to my surprise it also fixed the problem! From this I can only conclude there is some unknown issue in this module that is beyond the scope of OFN. With this long description of what I have tried and failed I hope you understand that I've did my best to find a better solution, but had no success in my search. Uninstalling and reinstalling the same thing was the only solution that worked. Why it is a problem only in Ubuntu 20 and not 18 and 16 is another mystery. In the future, if someone accepts the quest of removing this ugly fix, the first thing I suggest to check is if there is a version of `zzet.rbenv` newer than 3.6.0 and, if there is such version, check if it fixes the error described here. --- playbooks/provision.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/playbooks/provision.yml b/playbooks/provision.yml index 75da751cd..3a3cf4816 100644 --- a/playbooks/provision.yml +++ b/playbooks/provision.yml @@ -115,6 +115,12 @@ tags: logrotate tasks: + - name: Fix Ruby # noqa 301 + command: bash -lc "rbenv uninstall -f {{ ruby_version }} && rbenv install {{ ruby_version }}" + become: yes + become_user: "{{ app_user }}" + when: ansible_distribution_major_version >= '20' + - meta: flush_handlers # Ensure handlers run successfully before reporting success - name: notify slack From 415c8ffcf9950458864145e2fbb2987f024883a4 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Mon, 27 Jun 2022 10:30:42 -0300 Subject: [PATCH 6/6] Prevent Ruby fix for Ubuntu 20 to run when not necessary It is only necessary to run once per Ruby. Running it every time the provision playbook runs did not cause any error, but it took a while to run delaying deployments. --- playbooks/provision.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/playbooks/provision.yml b/playbooks/provision.yml index 3a3cf4816..f5b54d22c 100644 --- a/playbooks/provision.yml +++ b/playbooks/provision.yml @@ -116,7 +116,9 @@ tasks: - name: Fix Ruby # noqa 301 - command: bash -lc "rbenv uninstall -f {{ ruby_version }} && rbenv install {{ ruby_version }}" + command: + cmd: bash -lc "rbenv uninstall -f {{ ruby_version }} && rbenv install {{ ruby_version }} && touch ~/.rbenv/versions/{{ ruby_version }}/.reinstalled" + creates: "~/.rbenv/versions/{{ ruby_version }}/.reinstalled" become: yes become_user: "{{ app_user }}" when: ansible_distribution_major_version >= '20'