From 543f9fb5525341cd244fdae15b98c7da45764d50 Mon Sep 17 00:00:00 2001 From: Nikola Vidovic Date: Fri, 10 Oct 2014 12:28:36 +0200 Subject: [PATCH] Create postfix playbook - Install and configure postfix. - Add empty line. - Change restart to reload. - Add postmap, addresses, aliases and create folders. - Install and configure postfix. - Add empty line. - Rename postfix-service to postfix-handlers. - Use postfix reload instead of service reload feature. - Move postfix to webservers. - Add virtual_alias_maps to postfix playbook. - Move all from common to web folder. Fixes #6 Closes #33 --- site.yml | 6 ++++-- web/postfix-handlers.yml | 11 ++++++++++ web/postfix.yml | 43 ++++++++++++++++++++++++++++++++++++++++ web/postfix/addresses | 0 web/postfix/domains | 0 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 web/postfix-handlers.yml create mode 100644 web/postfix.yml create mode 100644 web/postfix/addresses create mode 100644 web/postfix/domains diff --git a/site.yml b/site.yml index 6163116..fa463c8 100644 --- a/site.yml +++ b/site.yml @@ -5,19 +5,20 @@ tasks: - include: common/bootstrap.yml - - name: configure and deploy the webservers and application code hosts: webservers remote_user: root tasks: - include: web/deploy.yml - - include: web/fastcgi.yml - include: web/git.yml + + - include: web/fastcgi.yml - include: web/mysql.yml - include: web/nginx-passenger.yml - include: web/nodejs.yml - include: web/php.yml + - include: web/postfix.yml - include: web/postgresql.yml - include: web/ruby.yml @@ -32,4 +33,5 @@ - include: web/mysql-handlers.yml - include: web/nginx-passenger-handlers.yml - include: web/php-fastcgi-handlers.yml + - include: web/postfix-handlers.yml - include: web/postgresql-handlers.yml diff --git a/web/postfix-handlers.yml b/web/postfix-handlers.yml new file mode 100644 index 0000000..a912c97 --- /dev/null +++ b/web/postfix-handlers.yml @@ -0,0 +1,11 @@ +--- + +- name: Reload postfix + command: /usr/sbin/postfix reload + +- name: Postmap addresses + command: postmap /etc/postfix/virtual/addresses + notify: Reload postfix + +- name: Restart postfix + action: service name=postfix state=restarted diff --git a/web/postfix.yml b/web/postfix.yml new file mode 100644 index 0000000..ea56c9a --- /dev/null +++ b/web/postfix.yml @@ -0,0 +1,43 @@ +--- + +- name: Install postfix + apt: name=postfix state=installed + +- name: Ensure that postfix is started and enabled on boot + service: name=postfix state=started enabled=yes + +- name: Set mailname + copy: dest=/etc/mailname content={{ inventory_hostname }} + +- name: Configure postfix + lineinfile: + regexp='{{ item.regexp }}' backrefs=yes line='{{ item.line }}' dest=/etc/postfix/main.cf + with_items: + - { regexp: '^#myorigin = /etc/mailname', line: 'myorigin = /etc/mailname' } + - { regexp: '^myhostname', line: 'myhostname = {{ inventory_hostname }}' } + - { regexp: '^mydestination', line: 'mydestination = $myhostname, /etc/postfix/virtual/domains, localhost, localhost.localdomain, localhost' } + notify: Restart postfix + +- name: Remove lines from postfix + lineinfile: + regexp='{{ item.regexp }}' backrefs=yes dest=/etc/postfix/main.cf state=absent + with_items: + - { regexp: '^alias_maps' } + - { regexp: '^alias_database' } + notify: Reload postfix + +- name: Add virtual_alias_maps line + lineinfile: line='virtual_alias_maps = hash:/etc/postfix/virtual/addresses' + dest=/etc/postfix/main.cf + notify: Reload postfix + +- name: Ensure that Postfix virtual folder exsists + file: path=/etc/postfix/virtual state=directory + +- name: Configure addresses for postfix + copy: src=web/postfix/addresses dest=/etc/postfix/virtual/addresses + notify: Postmap addresses + +- name: Configure domains for postfix + copy: src=web/postfix/domains dest=/etc/postfix/virtual/domains + notify: Reload postfix diff --git a/web/postfix/addresses b/web/postfix/addresses new file mode 100644 index 0000000..e69de29 diff --git a/web/postfix/domains b/web/postfix/domains new file mode 100644 index 0000000..e69de29