Skip to content

Commit

Permalink
refactor(states): split exim metastate in .package/.config/.service
Browse files Browse the repository at this point in the history
  • Loading branch information
n-rodriguez committed Sep 20, 2019
1 parent 5b815e6 commit a947ba9
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 65 deletions.
17 changes: 13 additions & 4 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ exim-formula
:scale: 100%
:target: https://github.com/semantic-release/semantic-release

Formula to install and configure the exim mail server.

Formula to install and configure the exim mail server.

.. contents:: **Table of Contents**

Expand Down Expand Up @@ -46,12 +45,22 @@ Available states
.. contents::
:local:


``exim``
^^^^^^^^

Install the ``exim`` package and enable the service.

``exim.package``
^^^^^^^^^^^^^^^^
Installs the exim package.

``exim.config``
^^^^^^^^^^^^^^^
This state manages the file ``update-exim4.conf.conf`` under ``/etc/exim4`` (template found in "exim/files"). The configuration is populated by values in "exim/map.jinja" based on the package's default values (and RedHat, Debian, Suse and Arch family distribution specific values), which can then be overridden by values of the same name in pillar.

``exim.service``
^^^^^^^^^^^^^^^^
Manages the startup and running state of the exim service.

Testing
-------

Expand Down
48 changes: 48 additions & 0 deletions exim/config/file.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_package_install = tplroot ~ '.package.install' %}
{%- from tplroot ~ "/map.jinja" import map with context %}
{% set use_split_config = salt['pillar.get']('exim:config:use_split_config', 'true') %}
{% set configtype = salt['pillar.get']('exim:config:configtype', 'satellite') %}
{% set hide_mailname = salt['pillar.get']('exim:config:hide_mailname', 'true') %}
{% set ue4c_keepcomments = salt['pillar.get']('exim:config:ue4c_keepcomments', 'true') %}
{% set localdelivery = salt['pillar.get']('exim:config:localdelivery', 'mail_spool') %}
{% set local_interfaces = salt['pillar.get']('exim:config:local_interfaces', '') %}
{% set minimaldns = salt['pillar.get']('exim:config:minimaldns', 'false') %}
{% set other_hostnames = salt['pillar.get']('exim:config:other_hostnames', '') %}
{% set readhost = salt['pillar.get']('exim:config:readhost', '') %}
{% set relay_domains = salt['pillar.get']('exim:config:relay_domains', '') %}
{% set relay_nets = salt['pillar.get']('exim:config:relay_nets', '') %}
{% set smarthost = salt['pillar.get']('exim:config:smarthost', '') %}
{% set cfilemode = salt['pillar.get']('exim:config:cfilemode', '644') %}
{{ map.config_dir }}/{{ map.config_file }}:
file.managed:
- contents: |
dc_eximconfig_configtype='{{ configtype }}'
dc_other_hostnames='{{ other_hostnames }}'
dc_local_interfaces='{{ local_interfaces }}'
dc_relay_domains='{{ relay_domains }}'
dc_relay_nets='{{ relay_nets }}'
dc_use_split_config='{{ use_split_config }}'
dc_hide_mailname='{{ hide_mailname }}'
ue4c_keepcomments='{{ ue4c_keepcomments }}'
dc_localdelivery='{{ localdelivery }}'
dc_minimaldns='{{ minimaldns }}'
dc_readhost='{{ readhost }}'
dc_smarthost='{{ smarthost }}'
CFILEMODE='{{ cfilemode }}'
{% if salt['pillar.get']('exim:files') %}
{% for dir in map.sub_dirs %}
{% for file in salt['pillar.get']('exim:files:' + dir, {}) %}
{{ map.config_dir }}/conf.d/{{ dir }}/{{ file }}:
file.managed:
- contents_pillar: exim:files:{{ dir }}:{{ file }}
{% endfor %}
{% endfor %}
{% endif %}
5 changes: 5 additions & 0 deletions exim/config/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .file
67 changes: 6 additions & 61 deletions exim/init.sls
Original file line number Diff line number Diff line change
@@ -1,62 +1,7 @@
# This is the main state file for configuring exim,

{% from "exim/map.jinja" import map with context %}
exim_install_packages:
pkg.installed:
- pkgs:
{% for pkg in map.pkgs %}
- {{ pkg }}
{% endfor %}
{% set use_split_config = salt['pillar.get']('exim:config:use_split_config', 'true') %}
{% set configtype = salt['pillar.get']('exim:config:configtype', 'satellite') %}
{% set hide_mailname = salt['pillar.get']('exim:config:hide_mailname', 'true') %}
{% set ue4c_keepcomments = salt['pillar.get']('exim:config:ue4c_keepcomments', 'true') %}
{% set localdelivery = salt['pillar.get']('exim:config:localdelivery', 'mail_spool') %}
{% set local_interfaces = salt['pillar.get']('exim:config:local_interfaces', '') %}
{% set minimaldns = salt['pillar.get']('exim:config:minimaldns', 'false') %}
{% set other_hostnames = salt['pillar.get']('exim:config:other_hostnames', '') %}
{% set readhost = salt['pillar.get']('exim:config:readhost', '') %}
{% set relay_domains = salt['pillar.get']('exim:config:relay_domains', '') %}
{% set relay_nets = salt['pillar.get']('exim:config:relay_nets', '') %}
{% set smarthost = salt['pillar.get']('exim:config:smarthost', '') %}
{% set cfilemode = salt['pillar.get']('exim:config:cfilemode', '644') %}
{{ map.config_dir }}/{{ map.config_file }}:
file.managed:
- contents: |
dc_eximconfig_configtype='{{ configtype }}'
dc_other_hostnames='{{ other_hostnames }}'
dc_local_interfaces='{{ local_interfaces }}'
dc_relay_domains='{{ relay_domains }}'
dc_relay_nets='{{ relay_nets }}'
dc_use_split_config='{{ use_split_config }}'
dc_hide_mailname='{{ hide_mailname }}'
ue4c_keepcomments='{{ ue4c_keepcomments }}'
dc_localdelivery='{{ localdelivery }}'
dc_minimaldns='{{ minimaldns }}'
dc_readhost='{{ readhost }}'
dc_smarthost='{{ smarthost }}'
CFILEMODE='{{ cfilemode }}'
- watch_in:
- service: {{ map.service }}
{% if salt['pillar.get']('exim:files') %}
{% for dir in map.sub_dirs %}
{% for file in salt['pillar.get']('exim:files:' + dir, {}) %}
{{ map.config_dir }}/conf.d/{{ dir }}/{{ file }}:
file.managed:
- contents_pillar: exim:files:{{ dir }}:{{ file }}
- watch_in:
- service: {{ map.service }}
{% endfor %}
{% endfor %}
{% endif %}
exim_service:
service.running:
- name: {{ map.service }}
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .package
- .config
- .service
5 changes: 5 additions & 0 deletions exim/package/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .install
10 changes: 10 additions & 0 deletions exim/package/install.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import map with context %}
exim/package/install:
pkg.installed:
- pkgs: {{ map.pkgs | json }}
5 changes: 5 additions & 0 deletions exim/service/init.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

include:
- .running
17 changes: 17 additions & 0 deletions exim/service/running.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- set sls_config_file = tplroot ~ '.config.file' %}
{%- from tplroot ~ "/map.jinja" import map with context %}
include:
- {{ sls_config_file }}
exim/service/running:
service.running:
- name: {{ map.service }}
- enable: true
- require:
- sls: {{ sls_config_file }}

0 comments on commit a947ba9

Please sign in to comment.