- name: stopmonit
  become: yes
  service:
    name: monit
    state: stopped

# temporary remove formerly entry in /etc/ssh/ssh_config
- name: remove sshd allow root from pf-backup v1
  become: yes
  replace:
    path: /etc/ssh/sshd_config
    regexp: '# Backups ssh login from BackupPC 21.5.2021 skalinowski\nMatch Host 192.168.42.100\nPermitRootLogin prohibit-password'
    replace: ''
  notify: restart sshd

#- name: remove sshd allow root from pf-backup v2 with sourounding markers
#  become: yes
#  blockinfile:
#    path: /etc/ssh/sshd_config
#    marker: "#### {mark} ANSIBLE MANAGED pf-backup root login ####"
#    content: ""
#  notify: restart sshd

- name: reenable root-login from pf-backup - some hosts do not read /etc/ssh/sshd_config.d/80-backuppc.conf
  become: yes
  blockinfile:
    path: /etc/ssh/sshd_config
    marker: "#### {mark} ANSIBLE MANAGED pf-backup root login ####"
    content: |
      #
      # allow ssh login from BackupPC, Jan 2022, ansible/skalinowski
      # temporary allow because sshd_config.d/80-backuppc.conf is not active
      #
      Match Host 192.168.42.100
      PermitRootLogin prohibit-password
      AllowUsers perfact root
  notify: restart sshd
  when: ansible_facts['distribution'] == "Ubuntu" and ( ansible_facts['distribution_version'] == "18.04" or ansible_facts['distribution_version'] == "20.04")

- name: create dir /etc/ssh/sshd_config.d
  become: yes
  file:
    path: /etc/ssh/sshd_config.d
    state: directory
    owner: root
    mode: 0755

- name: modify sshd allow root from pf-backup
  become: yes
  copy:
    content: |
      #### BEGIN ANSIBLE MANAGED pf-backup root login ####
      #
      # allow ssh login from BackupPC, Jan 2022, ansible/skalinowski
      #
      Match Host 192.168.42.100
      PermitRootLogin prohibit-password
      AllowUsers perfact root
      #### END ANSIBLE MANAGED pf-backup root login ####
    dest: /etc/ssh/sshd_config.d/80-backuppc.conf
    mode: 0644
  notify: restart sshd

- name: startmonit
  become: yes
  service:
    name: monit
    state: started
