diff --git a/linux-config-relayhost-smtp.yaml b/linux-config-relayhost-smtp.yaml new file mode 100644 index 0000000..cac4a65 --- /dev/null +++ b/linux-config-relayhost-smtp.yaml @@ -0,0 +1,12 @@ +--- + +- hosts: '{{ ip_addr }}' + become: yes + become_method: sudo + gather_facts: yes + + tasks: + + - name: "[CONFIG RELAYHOST SMTP] Config relayhost smtp" + import_role: + name: config-relayhost-smtp \ No newline at end of file diff --git a/roles/config-relayhost-smtp/defaults/main.yaml b/roles/config-relayhost-smtp/defaults/main.yaml new file mode 100644 index 0000000..1df9485 --- /dev/null +++ b/roles/config-relayhost-smtp/defaults/main.yaml @@ -0,0 +1,14 @@ +--- +exim_dc_eximconfig_configtype: satellite +dc_other_hostnames: "{{ ansible_nodename }}" +dc_local_interfaces: 127.0.0.1 +dc_readhost: "{{ ansible_nodename }}" +dc_relay_domains: "" +dc_minimaldns: false +dc_relay_nets: "" +dc_smarthost: smtp.verdnatura.es +CFILEMODE: 644 +dc_use_split_config: false +dc_hide_mailname: true +dc_mailname_in_oh: true +dc_localdelivery: mail_spool \ No newline at end of file diff --git a/roles/config-relayhost-smtp/handlers/main.yaml b/roles/config-relayhost-smtp/handlers/main.yaml new file mode 100644 index 0000000..c9f53d9 --- /dev/null +++ b/roles/config-relayhost-smtp/handlers/main.yaml @@ -0,0 +1,6 @@ +--- +# restart exim4 service to apply changes +- name: restart exim4 + service: + name: "{{ exim_daemon }}" + state: restarted \ No newline at end of file diff --git a/roles/config-relayhost-smtp/tasks/main.yaml b/roles/config-relayhost-smtp/tasks/main.yaml new file mode 100644 index 0000000..4b908de --- /dev/null +++ b/roles/config-relayhost-smtp/tasks/main.yaml @@ -0,0 +1,51 @@ +#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +# Reconfigure relayhost smtp to smtp.verdnatura.es +- name: reconfigure relayhost to smtp.verdnatura.es + lineinfile: + dest: "{{ exim_configuration_file }}" + regexp: "{{ item.regexp }}" + line: "{{ item.line }}" + state: present + mode: 0644 + with_items: + - regexp: '^dc_eximconfig_configtype' + line: "dc_eximconfig_configtype='{{ exim_dc_eximconfig_configtype }}'" + - regexp: '^dc_other_hostnames' + line: "dc_other_hostnames='{{ dc_other_hostnames }}'.verdnatura.es" + - regexp: '^dc_local_interfaces' + line: "dc_local_interfaces='{{ dc_local_interfaces }}'" + - regexp: '^dc_readhost' + line: "dc_readhost='{{ dc_readhost }}'.verdnatura.es" + - regexp: '^dc_relay_domains' + line: "dc_relay_domains='{{ dc_relay_domains }}'" + - regexp: '^dc_minimaldns' + line: "dc_minimaldns='{{ dc_minimaldns }}'" + - regexp: '^dc_relay_nets' + line: "dc_relay_nets='{{ dc_relay_nets }}'" + - regexp: '^dc_smarthost' + line: "dc_smarthost='{{ dc_smarthost }}'" + - regexp: '^CFILEMODE' + line: "CFILEMODE='{{ CFILEMODE }}'" + - regexp: '^dc_use_split_config' + line: "dc_use_split_config='{{ dc_use_split_config }}'" + - regexp: '^dc_hide_mailname' + line: "dc_hide_mailname='{{ dc_hide_mailname }}'" + - regexp: '^dc_mailname_in_oh' + line: "dc_mailname_in_oh='{{ dc_mailname_in_oh }}'" + - regexp: '^dc_localdelivery' + line: "dc_localdelivery='{{ dc_localdelivery }}'" + notify: restart exim4 + register: exim4_config +#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +# service should start on boot. +- name: service should start on boot + service: + name: "{{ exim_daemon }}" + enabled: yes +#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +# Send mail to verify relay-host +- name: sending mail to verify exim4 config works + shell: echo "Verify send email from host {{ ansible_nodename }}.verdnatura.es with mailx , bye." | mailx -s "test mail verify exim4 for the host {{ ansible_nodename }}.verdnatura.es" -c rubenb@verdnatura.es,nada@verdnatura.es,juan@verdnatura.es,davidl@verdnatura.es sysadmin@verdnatura.es + when: exim4_config.changed +#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/roles/config-relayhost-smtp/vars/main.yaml b/roles/config-relayhost-smtp/vars/main.yaml new file mode 100644 index 0000000..82108ac --- /dev/null +++ b/roles/config-relayhost-smtp/vars/main.yaml @@ -0,0 +1,3 @@ +--- +exim_configuration_file: /etc/exim4/update-exim4.conf.conf +exim_daemon: exim4