You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.6 KiB

# dotqmail/tasks/main.yml
# Copyright 2016 Jonathan Golder <>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
# tasks file for dotqmail
# To decide wether a dotqmail file is still needed we need to get all files
- name: Fetch all present dotqmail files
paths: "{{ansible_env.HOME}}/"
patterns: "{{dotqmail_prefix}}*"
hidden: True
register: present_files
# To decide which file could be deleted we extract first the file name of
# current file with basename(path) and then replace the dotqmail_prefix in it
# with the empty string via replace(dotqmail_prefix,'') to get the dotqmail
# extention
# Then we check up if a member with this extenion is defined in our
# dotqmail_files dict. If not, we can finaly delete the file (current item) via
# item.path
- name: Delete unconfigured (old) files
path: "{{item.path}}"
state: absent
current_ext: "{{item.path|basename|replace(dotqmail_prefix,'')}}"
with_items: "{{present_files.files}}"
when: dotqmail_files[current_ext] is not defined
# Going forward to create/update files with config
# Since the root file has no extention we need to treat it separately
# The content lines are configured in list dotqmail_rootfile
- name: generate/update dotqmail root file
src: templates/dotqmail.j2
dest: "{{ansible_env.HOME}}/{{file}}"
mode: 0600
file: ".qmail"
file_lines: "{{dotqmail_rootfile}}"
# For the other files the we get a key-value pair with the dotqmail extention
# as key and the list of lines as value while looping over dotqmail_files
# (which is a combination of dotqmail_config_files from inventory over
# dotqmail_default_files from role defaults)
- name: generate/update other dotqmail-files
src: templates/dotqmail.j2
dest: "{{ansible_env.HOME}}/{{file}}"
mode: 0600
file: "{{dotqmail_prefix}}{{item.key}}"
file_lines: "{{item.value}}"
with_dict: "{{dotqmail_files}}"