---
  - name: Add BeyondTrust PBIS open apt repo key
    apt_key:
     url: http://repo.pbis.beyondtrust.com/apt/RPM-GPG-KEY-pbis
     state: present
    become: yes

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

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

  # If likewise-open is installed this will replace it and migrate
  # most of its configuration.
  - name: Install pbis-open
    apt:
      name: pbis-open
      state: latest
    become: yes

  - name: Write nsswitch.conf
    template:
      src: templates/nsswitch.conf
      dest: /etc/nsswitch.conf
    become: yes

  # Migrating to pbis-open resets the default shell setting.
  - name: Check current default shell
    command: "/opt/pbis/bin/config --show LoginShellTemplate"
    register: default_shell
    changed_when: no
    check_mode: no

  - name: Set default shell
    command: "/opt/pbis/bin/config LoginShellTemplate /bin/bash"
    become: yes
    when: "'/bin/sh' in default_shell.stdout"
