Skip to content

Commit

Permalink
Added postfix_files feature as a simple means to add extra files/maps…
Browse files Browse the repository at this point in the history
… to the postfix config
  • Loading branch information
Thulium-Drake authored and richm committed Jul 9, 2024
1 parent 9f52769 commit 73b7c72
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ postfix_conf:
relayhost: example.com
```

### postfix_files

```yaml
postfix_files:
- name: sasl_passwd
content: example.com user:password
postmap: true
- name: sender_canonical_maps
content: /.+/ info@example.com
```

This is a list of files that will be placed in /etc/postfix and that can be converted into Postfix Lookup Tables if needed.

It's meant as a simple mechanism to configure things such as SASL credentials and other small snippets.

### postfix_check

```yaml
Expand Down
9 changes: 9 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
#
postfix_conf: {}

# Additional config maps/files, e.g.:
# postfix_files:
# - name: 'sasl_passwd'
# content: 'smtp.example.com user@example.com:myFirstPassword
# postmap: true
# - name: 'sender_canonical_maps'
# content: '/.+/ user@example.com'
postfix_files: []

# Whether to run 'postfix check' before it's started
postfix_check: true

Expand Down
27 changes: 27 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,33 @@
{% endif %}
{% endfor %}
- name: Configure additional files
copy:
content: "{{ file['content'] }}"
dest: /etc/postfix/{{ file['name'] }}
owner: root
group: root
mode: '0640'
loop: "{{ postfix_files }}"
register: __postfix_postmap_files
no_log: true
loop_control:
loop_var: file
notify:
- Check postfix
- Restart postfix

- name: Postmap files
command: postmap {{ result["dest"] | quote }}
when:
- result["changed"]
- result["file"]["postmap"] | d(false)
no_log: true
changed_when: true
loop: "{{ __postfix_postmap_files['results'] }}"
loop_control:
loop_var: result

- name: Apply changes
when: __postfix_has_config_changed | d("") is search("True")
block:
Expand Down
33 changes: 33 additions & 0 deletions tests/tests_set_file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Create a postmapped file
hosts: all

vars:
postfix_files:
- name: test
content: test
postmap: true

tasks:
- name: Run the role with test postmap file
include_role:
name: linux-system-roles.postfix
public: true

- name: Check if postmap file exists
stat:
path: /etc/postfix/test.db
register: test_file
changed_when: false

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

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

0 comments on commit 73b7c72

Please sign in to comment.