---
# tasks file for pbis
  - name: add BeyondTrust PBIS open apt repo key
    apt_key:
     url: http://repo.pbis.beyondtrust.com/apt/RPM-GPG-KEY-pbis
     state: present

  - name: add BeyondTrust PBIS open apt repo
    apt_repository:
      repo: 'deb http://repo.pbis.beyondtrust.com/apt pbiso main'
      state: present

  - name: apt-get update
    apt:
      update_cache: yes
      cache_valid_time: 3600

  - name: apt-get install pbis-open
    apt:
      name: pbis-open
      state: latest

  - name: enable lsass to nsswitch.conf
    template:
      src: templates/nsswitch.conf
      dest: /etc/nsswitch.conf

  - name: Check the Domain status
    shell: /opt/pbis/bin/lsa get-status | grep Netbios | awk '{print $3}'
    register: domain_status

  - debug:
      msg: status is {{ domain_status }}

  - name: Join the machine if it is not already on the domain.
    shell: "{{ item }}"
    async: 1
    poll: 0
    with_items:
      - /opt/pbis/bin/config LoginShellTemplate "/bin/bash"
      - /opt/pbis/bin/config AssumeDefaultDomain true
      - /opt/pbis/bin/config HomeDirTemplate "%H/%U"
      - domainjoin-cli join --ou "ZOOX/Application Services/Servers/Pipedream" corp.zooxlabs.com svc-pd-ad-bind '{{ lookup('hashi_vault', 'secret=secret/ad/slurm_enroll_key').value }}'
      - domainjoin-cli configure --enable pam
    no_log: False
    when: domain_status.stdout != 'ZOOXLABS'
