Skip to content

Commit

Permalink
feat: support postfix_default_database_type
Browse files Browse the repository at this point in the history
Feature: The role will determine the default database type used by postfix
and will export that value as the variable `postfix_default_database_type`

Reason: Users need to be able to set configuration parameter values
based on the database type.

Result: Users can set configuration parameter values based on the
default database type.

Signed-off-by: Rich Megginson <[email protected]>
  • Loading branch information
richm committed Dec 2, 2024
1 parent 681f7fa commit e4e1ced
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ It cannot be used for *removing* policy.
If you want to remove policy, you will need to use the selinux system
role directly.

## Variables Exported by the Role

### postfix_default_database_type

This is a string which specifies the default database type used by postfix,
which is obtained by using `postconf -h default_database_type`. This can be
used to set configuration which depends on the type:

```yaml
- name: Manage postfix
hosts: all
vars:
postfix_conf:
relay_domains: "{{ postfix_default_database_type }}:/etc/postfix/relay_domains"
roles:
- linux-system-roles.postfix
```

## Limitations

There is no way to remove separate configuration parameters.
Expand Down
9 changes: 9 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@
use: "{{ (__postfix_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"

- name: Get default database type from postconf
command: postconf -h default_database_type
changed_when: false
register: __postfix_register_dbtype

- name: Set postfix_default_database_type
set_fact:
postfix_default_database_type: "{{ __postfix_register_dbtype.stdout | trim }}"

- name: Enable Postfix
service:
name: postfix
Expand Down
26 changes: 17 additions & 9 deletions tests/tests_set_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
- name: test
content: test
postmap: true
postfix_conf:
relay_domains: "{{
postfix_default_database_type }}:/etc/postfix/relay_domains"
__test_file_suffix: "{{ '.lmdb'
if postfix_default_database_type == 'lmdb'
else '.db' }}"

tasks:
- name: Run the role with test postmap file
Expand All @@ -19,20 +25,22 @@
path: /etc/postfix/test{{ __test_file_suffix }}
register: test_file
changed_when: false
vars:
__test_file_suffix: "{{ '.lmdb' if ansible_facts['os_family'] == 'RedHat'
and ansible_facts['distribution'] != 'Fedora'
and ansible_facts['distribution_major_version'] is version('10', '>=')
else '.db' }}"

- name: Assert file is present
assert:
that: test_file.stat.exists

- name: Get relay_domains
command: postconf -h relay_domains
changed_when: false
register: __test_relay_domains

- name: Check relay_domains
assert:
that: __test_relay_domains.stdout | trim ==
postfix_default_database_type ~ ":/etc/postfix/relay_domains"

- name: Clean up test files
file:
path: "{{ item }}"
path: /etc/postfix/test{{ __test_file_suffix }}
state: absent
loop:
- /etc/postfix/test
- /etc/postfix/test.db

0 comments on commit e4e1ced

Please sign in to comment.