---
- name: Sync Configuration Files
  hosts: rhel
  become: yes
  vars:
    worker_limit: 1024  # Global variable used in the template

  tasks:
    - name: Deploy sssd.conf
      template:
        src: templates/sssd.conf
        dest: /etc/sssd/conf.d/sssd.conf
        owner: root
        group: root
        mode: '0600'
      notify: Restart sssd  # This triggers the handler only if the file changes

    - name: Deploy ldap.conf
      template:
        src: templates/ldap.conf
        dest: /etc/openldap/ldap.conf
        owner: root
        group: root
        mode: '0644'

    - name: Deploy sshd.conf
      template:
        src: templates/sshd.conf
        dest: /etc/ssh/sshd_config.d/60_lab.conf
        owner: root
        group: root
        mode: '0600'

    - name: Deploy ssh.conf
      template:
        src: templates/ssh.conf
        dest: /etc/ssh/ssh_config.d/60_lab.conf
        owner: root
        group: root
        mode: '0644'

    - name: Deploy sudoers
      template:
        src: templates/lab-sudo
        dest: /etc/sudoers.d/sudogroup
        owner: root
        group: root
        mode: '0644'

    - name: Root password
      user:
        name: root
        password: "$6$OJEdzUbqfQR72WjX$SFMnDZ0MXM7JfYKPvvN0nJIPetzrWQw/0q360xgR9mwJVwrme4dt9hhtH95yytn8Ln0.0koVCno6vskylJFm5."

    - name: Disable SELinux
      ansible.builtin.selinux:
        state: disabled

    - name: Create bin directory
      file:
        path: /opt/atclab/bin
        state: directory
        mode: '0755'
        owner: root
        group: root

    - name: Copy etc configs
      copy:
        src: etc/profile.d/
        dest: /etc/profile.d/
        owner: root
        group: root
        mode: '0644'

    - name: Copy bin scripts
      copy:
        src: bin/
        dest: /opt/atclab/bin
        owner: root
        group: root
        mode: '0755'

    - name: Enable AutoFS
      ansible.builtin.systemd:
        name: autofs
        state: started
        enabled: yes

  handlers:
    - name: Restart sssd
      service:
        name: sssd
        state: restarted

