From c7be9e4d5b89aacfe3cc8b424b191b2a2b6c2855 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Thu, 30 Apr 2026 21:52:30 +1200 Subject: [PATCH] odbc: add Arch Linux support via AUR psqlodbc (#11944) * test(odbc): add Arch Linux support via AUR psqlodbc Fixes #4267 * test(setup_postgresql_db): guard Arch Linux initdb with creates * test(odbc): add setup_remote_tmp_dir dependency --- .../targets/odbc/handlers/main.yml | 15 +++++ tests/integration/targets/odbc/meta/main.yml | 1 + .../targets/odbc/tasks/install_arch_odbc.yml | 56 +++++++++++++++++++ tests/integration/targets/odbc/tasks/main.yml | 12 +++- .../setup_postgresql_db/tasks/main.yml | 2 + 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 tests/integration/targets/odbc/handlers/main.yml create mode 100644 tests/integration/targets/odbc/tasks/install_arch_odbc.yml diff --git a/tests/integration/targets/odbc/handlers/main.yml b/tests/integration/targets/odbc/handlers/main.yml new file mode 100644 index 0000000000..b49e13ba33 --- /dev/null +++ b/tests/integration/targets/odbc/handlers/main.yml @@ -0,0 +1,15 @@ +--- +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +- name: Remove user odbcbuilder + ansible.builtin.user: + name: odbcbuilder + state: absent + remove: true + +- name: Remove odbcbuilder sudoers + community.general.sudoers: + name: odbcbuilder + state: absent diff --git a/tests/integration/targets/odbc/meta/main.yml b/tests/integration/targets/odbc/meta/main.yml index 0d06eaa398..9023ef1c95 100644 --- a/tests/integration/targets/odbc/meta/main.yml +++ b/tests/integration/targets/odbc/meta/main.yml @@ -5,4 +5,5 @@ dependencies: - setup_pkg_mgr + - setup_remote_tmp_dir - setup_postgresql_db diff --git a/tests/integration/targets/odbc/tasks/install_arch_odbc.yml b/tests/integration/targets/odbc/tasks/install_arch_odbc.yml new file mode 100644 index 0000000000..6c058d9e65 --- /dev/null +++ b/tests/integration/targets/odbc/tasks/install_arch_odbc.yml @@ -0,0 +1,56 @@ +--- +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +# psqlodbc is only available in the AUR on Arch Linux, so we must build it. +# makepkg cannot run as root, so we create a temporary build user with sudo. + +- name: Create AUR build user + ansible.builtin.user: + name: odbcbuilder + state: present + notify: Remove user odbcbuilder + +- name: Grant sudo powers to build user + community.general.sudoers: + name: odbcbuilder + user: odbcbuilder + commands: ALL + nopassword: true + notify: Remove odbcbuilder sudoers + +- name: Install AUR build dependencies + ansible.builtin.package: + name: + - base-devel + - git + - postgresql-libs + state: present + +- name: Allow build user to write to remote_tmp_dir + ansible.builtin.file: + path: "{{ remote_tmp_dir }}" + mode: "0777" + +- name: Create build directory for psqlodbc + ansible.builtin.file: + path: "{{ remote_tmp_dir }}/odbcbuilder/psqlodbc" + owner: odbcbuilder + state: directory + mode: "0755" + +- name: Clone psqlodbc from AUR + become: true + become_user: odbcbuilder + ansible.builtin.git: + repo: https://aur.archlinux.org/psqlodbc.git + dest: "{{ remote_tmp_dir }}/odbcbuilder/psqlodbc" + depth: 1 + +- name: Build and install psqlodbc + become: true + become_user: odbcbuilder + ansible.builtin.command: + chdir: "{{ remote_tmp_dir }}/odbcbuilder/psqlodbc" + cmd: makepkg -si --noconfirm diff --git a/tests/integration/targets/odbc/tasks/main.yml b/tests/integration/targets/odbc/tasks/main.yml index 7e2ae852f5..6fc753456c 100644 --- a/tests/integration/targets/odbc/tasks/main.yml +++ b/tests/integration/targets/odbc/tasks/main.yml @@ -12,7 +12,6 @@ msg: "{{ ansible_facts.os_family }} / {{ ansible_facts.distribution }} / {{ ansible_facts.distribution_major_version }}" - when: - - ansible_facts.os_family != 'Archlinux' # TODO install driver from AUR: https://aur.archlinux.org/packages/psqlodbc - ansible_facts.distribution != 'Debian' or ansible_facts.distribution_major_version != '13' # TODO fix tests for Debian 13 (Trixie)! block: @@ -23,6 +22,12 @@ - include_tasks: no_pyodbc.yml when: ansible_facts.os_family != 'FreeBSD' and ansible_facts.os_family != 'Suse' and ansible_facts.os_family != 'Debian' + # + # Install PostgreSQL ODBC driver from AUR on Arch Linux + # + - include_tasks: install_arch_odbc.yml + when: ansible_facts.os_family == 'Archlinux' + # # Get pyodbc installed # @@ -51,6 +56,11 @@ dsn: "DRIVER={PostgreSQL Unicode};Server=localhost;Port=5432;Database=postgres;Uid={{ my_user }};Pwd={{ my_pass_decrypted }};UseUnicode=True" when: ansible_facts.os_family == 'Debian' + - name: Changing DSN for Arch Linux + set_fact: + dsn: "DRIVER={/usr/lib/psqlodbcw.so};Server=localhost;Port=5432;Database=postgres;Uid={{ my_user }};Pwd={{ my_pass_decrypted }};UseUnicode=True" + when: ansible_facts.os_family == 'Archlinux' + # # Name setup database # diff --git a/tests/integration/targets/setup_postgresql_db/tasks/main.yml b/tests/integration/targets/setup_postgresql_db/tasks/main.yml index f8b950c8cc..b7a353df61 100644 --- a/tests/integration/targets/setup_postgresql_db/tasks/main.yml +++ b/tests/integration/targets/setup_postgresql_db/tasks/main.yml @@ -100,6 +100,8 @@ - name: Initialize postgres (Archlinux) command: su - postgres -c "initdb --locale en_US.UTF-8 -D '/var/lib/postgres/data'" + args: + creates: /var/lib/postgres/data/PG_VERSION when: ansible_facts.os_family == "Archlinux" - name: Initialize postgres (Alpine)