---
#
# https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_intro.html
#
- name: Provision new machines
  hosts: all
  # remote_user: root

  tasks:
  - name: Install/update apt packages
    include_role:
      name: provisioning
      tasks_from: raspian-apt
    when: ansible_distribution == "Debian"

  - name: Install/update yum packages
    include_role:
      name: provisioning
      tasks_from: fedora-yum
    when: ansible_distribution == "Fedora"

  - name: Stop automatic sleep
    ansible.builtin.systemd:
      state: stopped
      name: sleep.target
      masked: yes
    become: true

  - name: Stop automatic suspend
    ansible.builtin.systemd:
      state: stopped
      name: suspend.target
      masked: yes
    become: true

  - name: Stop automatic hibernate
    ansible.builtin.systemd:
      state: stopped
      name: hibernate.target
      masked: yes
    become: true

  - name: Set authorized key
    ansible.posix.authorized_key:
      user: dale
      state: present
      key: "{{ lookup('file', '/home/dale/.ssh/id_rsa.pub') }}"

  - name: Install/update apt packages
    include_role:
      name: provisioning
      tasks_from: snmpd

  - name: Install/update apt packages
    include_role:
      name: provisioning
      tasks_from: bash_dotfiles

#  - name: Install/update apt packages
#    include_role:
#      name: provisioning
#      tasks_from: vim_dotfiles

#  - name: Copy bash dotfiles to user
#    ansible.builtin.copy:
#      src: /home/dale/git/files/bash/
#      dest: /home/dale/tmp/
#      owner: dale
#      group: dale
#
#  - name: Write the apache config file
#    ansible.builtin.template:
#      src: /srv/httpd.j2
#      dest: /etc/httpd.conf
#
#- name: Update db servers
#  hosts: databases
#  remote_user: root
#
#  tasks:
#  - name: Ensure postgresql is at the latest version
#    ansible.builtin.yum:
#      name: postgresql
#      state: latest
#
#  - name: Ensure that postgresql is started
#    ansible.builtin.service:
#      name: postgresql
#      state: started
