Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ based on system resources. To disable the tuning, set the
postgresql_server_tuning: false
```

However, when running against a
[buildah connection](https://docs.ansible.com/ansible/latest/collections/containers/podman/buildah_connection.html),
i.e. a container build, this defaults to `false`. The available RAM during a
container build is independent of the actual deployment.

See the [`examples/`](examples) for details.

## Idempotence
Expand Down
5 changes: 4 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ postgresql_version: "{{ '16' if ansible_facts['os_family'] == 'RedHat'
else '13' }}"
postgresql_password: null
postgresql_cert_name: null
postgresql_server_tuning: true
# the container build environment's RAM is independent from the deployment
# (regardless if it's a bootc or system container one), so disable tuning there
# by default
postgresql_server_tuning: "{{ false if (ansible_connection | d('')) == 'buildah' else true }}"
postgresql_ssl_enable: false

# If you want to generate the certificas in the postgresql role
Expand Down
5 changes: 5 additions & 0 deletions tests/tasks/install_and_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
include_role:
name: linux-system-roles.postgresql
public: true
when: __run_role | d(true) | bool

- name: Flush handlers
meta: flush_handlers
Expand Down Expand Up @@ -53,6 +54,8 @@
when:
- __test_check_unix_socket | d(true)
- __postgresql_is_booted | bool
# role ran in container, disabled tuning
- not (__bootc_validation | d(false))

- name: Check - server tuning is used - effective cache size
become: true
Expand All @@ -74,6 +77,8 @@
when:
- __test_check_unix_socket | d(true)
- __postgresql_is_booted | bool
# role ran in container, disabled tuning
- not (__bootc_validation | d(false))

- name: Check postgresql version matches postgresql_version
command: postgres --version
Expand Down
29 changes: 29 additions & 0 deletions tests/tests_bootc_e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-License-Identifier: MIT
---
- name: Bootc end-to-end test
hosts: all
tags:
- tests::bootc-e2e
gather_facts: false
tasks:
- name: Bootc image build preparation
when: ansible_connection | d("") == "buildah"
block:
- name: Run postgresql role
include_role:
name: linux-system-roles.postgresql

- name: Create QEMU deployment
delegate_to: localhost
command: "{{ lsr_scriptdir }}/bootc-buildah-qcow.sh {{ ansible_host }}"
changed_when: true

- name: Validation of deployed image
when: ansible_connection | d("") != "buildah"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under what conditions can ansible_connection be undefined? Because above you reference it without the | d() in postgresql_server_tuning: "{{ false if ansible_connection == 'buildah' else true }}" ?

Copy link
Contributor Author

@martinpitt martinpitt Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ansible_connection is undefined for QEMU runs, i.e. when not using an external connection plugin.

Without the | d() it fails like this:

TASK [Flush handlers] ******************************************************************************************************************
task path: /var/home/martin/upstream/lsr/postgresql/tests/tasks/install_and_check.yml:11
Tuesday 03 June 2025  18:48:02 +0200 (0:00:00.017)       0:00:00.082 ********** 
ERROR! The conditional check 'ansible_connection != "buildah"' failed. The error was: error while evaluating conditional (ansible_connection != "buildah"): 'ansible_connection' is undefined. 'ansible_connection' is undefined

The error appears to be in '/var/home/martin/upstream/lsr/postgresql/tests/tasks/install_and_check.yml': line 11, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

Apparently Ansible gets along with testing for equality == against an undefined value, but not with !=. However, that's confusing, and I applied the default everywhere now for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ansible_connection is undefined for QEMU runs, i.e. when not using an external connection plugin.

That's really strange. I cannot reproduce this behavior. No matter what I try, I get "ansible_connection": "ssh" unless I explicitly specify another connection type.

Without the | d() it fails like this:

TASK [Flush handlers] ******************************************************************************************************************
task path: /var/home/martin/upstream/lsr/postgresql/tests/tasks/install_and_check.yml:11
Tuesday 03 June 2025  18:48:02 +0200 (0:00:00.017)       0:00:00.082 ********** 
ERROR! The conditional check 'ansible_connection != "buildah"' failed. The error was: error while evaluating conditional (ansible_connection != "buildah"): 'ansible_connection' is undefined. 'ansible_connection' is undefined

The error appears to be in '/var/home/martin/upstream/lsr/postgresql/tests/tasks/install_and_check.yml': line 11, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

Can you provide your exact tox command line?

Apparently Ansible gets along with testing for equality == against an undefined value, but not with !=.

That is even stranger.

However, that's confusing, and I applied the default everywhere now for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prep (works):

LSR_CONTAINER_PROFILE=false LSR_CONTAINER_PRETTY=false tox -e container-ansible-core-2.16 -- --image-name centos-9-bootc tests/tests_bootc_e2e.yml

Validate:

tox -e qemu-ansible-core-2.16 -- --image-file `pwd`/tests/tmp/tests_bootc_e2e/qcow2/disk.qcow2 --log-level=debug -e __bootc_validation=true -- tests/tests_bootc_e2e.yml

Perhaps you forgot the -e __bootc_validation=true?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable reference is in a handler - code run in handlers is in a strange variable namespace - I have seen cases where vars defined in the playbook are not available in the handler - but this one doesn't make any sense - if I put a debug var: ansible_connection at the beginning of the playbook, it prints the value - I have no idea why it would be removed before the handler is run - I'll chalk this up to a bug in ansible that we have to workaround.

block:
- name: Test default settings
include_tasks: tasks/install_and_check.yml
vars:
__run_role: false
__test_clean_instance: false
__postgresql_is_booted: true
Loading