---
#   Disable user at pf-mail
#   Unser info comes from datadir
#   vars:
#     USERLOGIN is given to playbook on commandline
#     vault_gitea_apikey comes from VAULTS internalit/vault_perfact_useradmin.yml
#     users[USERLOGIN].first_name
#     users[USERLOGIN].last_name
#     users[USERLOGIN].mail_address

- name: perfact_deluser - exit if USERLOGIN is not given on commandline
  meta: end_play
  run_once: true
  when: USERLOGIN is undefined
  # always execute
  check_mode: false

- name: perfact_deluser disable user on pf-mail
  become: true
  ansible.builtin.user:
    name: "{{ USERLOGIN }}"
    password_lock: true

# Warning: do not remove account or virtual aliases. In most cases we need an
# autoresponder for all addresses
#- name: perfact_deluser virtual aliases
#  # IMPORTENT: this only works if the entry has the ansible markers
#  become: true
#  blockinfile:
#    path: /etc/postfix/virtual
#    marker: "# {mark} CREATED BY ANSIBLE can be modified manually {{ USERLOGIN }}"
#    block: ""
#- name: postmap virtual
#  become: true
#  command: postmap /etc/postfix/virtual

- name: perfact_deluser pf-mail commit to git
  become: true
  ansible.builtin.shell: 'git diff --quiet /etc/postfix/ || { git add /etc/shadow /etc/postfix/ && git commit -m "perfact_deluser {{ USERLOGIN }} - Changes by Ansible" }'
  args:
    chdir: /etc/

#- name: ende now and here
#  meta: end_play
