From 71e9575967cf6ecbf5733dec285781f3efa5702e Mon Sep 17 00:00:00 2001
From: Chris Coley <chris@codingallnight.com>
Date: Fri, 29 Jun 2018 22:53:19 -0700
Subject: [PATCH] Refactor the task that installs OS specific packages

Now the task installs the OS specific required packages, plus a list of
additional packages that are defined in the 'postfix__recommended_packages'
variable.
---
 defaults/main.yml                |  3 +++
 tasks/install-postfix.debian.yml |  5 +----
 tasks/main.yml                   | 14 +++++++++++++-
 vars/debian.yml                  |  8 ++++++++
 4 files changed, 25 insertions(+), 5 deletions(-)
 create mode 100644 vars/debian.yml

diff --git a/defaults/main.yml b/defaults/main.yml
index 64a6f3e..bab5522 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -1,4 +1,7 @@
 ---
+# Additional packages to install. These packages won't be configured.
+postfix__recommended_packages: []
+
 # The name of this mail system, set in '/etc/mailname'
 postfix__mailname: '{{ ansible_fqdn }}'
 
diff --git a/tasks/install-postfix.debian.yml b/tasks/install-postfix.debian.yml
index 446670b..582b8b7 100644
--- a/tasks/install-postfix.debian.yml
+++ b/tasks/install-postfix.debian.yml
@@ -13,9 +13,6 @@
     name: '{{ item }}'
     state: present
     cache_valid_time: 3600
-  with_items:
-    - postfix
-    - mailutils
-    - make
+  with_items: '{{["postfix", "make"] + postfix__recommended_packages }}'
 ...
 # vi: set ts=2 sts=2 sw=2 et ft=yaml:
diff --git a/tasks/main.yml b/tasks/main.yml
index b74e905..af289db 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,5 +1,17 @@
 ---
-- include_tasks: '{{ task_file }}'
+- name: Include OS-specific variables
+  include_vars: '{{ var_file }}'
+  loop_control:
+    loop_var: var_file
+  with_first_found:
+    - vars/{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml
+    - vars/{{ ansible_distribution | lower }}-{{ ansible_distribution_release | lower }}.yml
+    - vars/{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml
+    - vars/{{ ansible_distribution | lower }}.yml
+    - vars/{{ ansible_os_family | lower }}.yml
+
+- name: Include OS-specific tasks
+  include_tasks: '{{ task_file }}'
   loop_control:
     loop_var: task_file
   with_first_found:
diff --git a/vars/debian.yml b/vars/debian.yml
new file mode 100644
index 0000000..5589c1c
--- /dev/null
+++ b/vars/debian.yml
@@ -0,0 +1,8 @@
+---
+# This file overrides variables set in defaults/main.yml.
+# Full documentation of the variables is available in the file.
+
+postfix__recommended_packages:
+  - mailutils
+...
+# vi: set ts=2 sts=2 sw=2 et ft=yaml:
-- 
GitLab