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.

53 lines
1.8 KiB

---
# 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
find:
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
file:
path: "{{item.path}}"
state: absent
vars:
current_ext: "{{item.path|basename|replace(dotqmail_prefix,'')}}"
with_items: "{{present_files.files}}"
when: dotqmail_files[current_ext] is not defined
# Gooing 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
template:
src: templates/dotqmail.j2
dest: "{{ansible_env.HOME}}/{{file}}"
mode: 0600
vars:
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
template:
src: templates/dotqmail.j2
dest: "{{ansible_env.HOME}}/{{file}}"
mode: 0600
vars:
file: "{{dotqmail_prefix}}{{item.key}}"
file_lines: "{{item.value}}"
with_dict: "{{dotqmail_files}}"