/
postfix.yml
96 lines (84 loc) · 3.04 KB
/
postfix.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
# linux_postinstall postfix
- name: "postfix: Debug"
vars:
msg: |-
ansible_os_family: {{ ansible_os_family }}
lp_postfix_install: {{ lp_postfix_install }}
lp_postfix_enable: {{ lp_postfix_enable }}
lp_postfix_flush_handlers: {{ lp_postfix_flush_handlers }}
lp_postfix_rescue_end_host: {{ lp_postfix_rescue_end_host }}
lp_postfix_service: {{ lp_postfix_service }}
lp_postfix_main_conf:
{{ lp_postfix_main_conf|to_yaml(indent=2)|indent(2) }}
lp_postfix_packages:
{{ lp_postfix_packages|to_nice_yaml(indent=2)|indent(2) }}
lp_backup_conf: {{ lp_backup_conf }}
ansible.builtin.debug:
msg: "{{ '{}'.format(msg) }}"
when: lp_postfix_debug|bool
tags: lp_postfix_debug
- name: "postfix: Install packages"
ansible.builtin.import_role:
name: vbotka.linux_lib
tasks_from: install_package.yml
when: lp_postfix_install|bool
vars:
ll_ipkg_list: "{{ lp_postfix_packages }}"
ll_ipkg_state: "{{ lp_package_state }}"
ll_ipkg_autoremove: "{{ lp_packages_autoremove|bool }}"
ll_ipkg_rescue_end_host: "{{ lp_packages_rescue_end_host|bool }}"
ll_debug: "{{ lp_postfix_debug|bool }}"
tags: lp_postfix_packages
- name: "chrony: Configure, enable, start, or disable postfix"
block:
- name: "postfix: Configure /etc/postfix/main.cf"
ansible.builtin.lineinfile:
dest: /etc/postfix/main.cf
regexp: '^\s*{{ item.key }}\s*=\s*(.*)$'
line: "{{ item.key }} = {{ item.value }}"
backup: "{{ lp_backup_conf }}"
create: true
mode: '0644'
loop: "{{ lp_postfix_main_conf }}"
loop_control:
label: "{{ item.key }}: {{ item.value }}"
notify: reload postfix
tags: lp_postfix_conf
- name: "postfix: Service {{ state }} and {{ enable }}"
ansible.builtin.service:
name: "{{ lp_postfix_service }}"
state: "{{ state }}"
enabled: "{{ enabled }}"
register: result
vars:
enabled: "{{ lp_postfix_enable|bool|d(false) }}"
state: "{{ lp_postfix_state|d(default_state) }}"
default_state: "{{ enabled|ternary('started', 'stopped') }}"
enable: "{{ enabled|ternary('enabled', 'disabled') }}"
tags: lp_postfix_service
- name: "postfix: Debug service"
ansible.builtin.debug:
var: result
when: lp_postfix_debug|bool
rescue:
- name: "postfix: Print errors"
ansible.builtin.debug:
msg: |
[ERR] task {{ ansible_failed_task.name }} failed. End host.
ansible_failed_task:
{{ ansible_failed_task|to_yaml(indent=2)|indent(2) }}
ansible_failed_result:
{{ ansible_failed_result|to_yaml(indent=2)|indent(2) }}
- name: "postfix: End host"
ansible.builtin.meta: end_host
when:
- lp_postfix_rescue_end_host|bool
- not ansible_check_mode
- name: "postfix: Clear host errors"
ansible.builtin.meta: clear_host_errors
- name: "postfix: Flush handlers"
ansible.builtin.meta: flush_handlers
when: lp_postfix_flush_handlers|bool
# EOF
...