#!/usr/bin/expect -f

{% set computer_ou = '' %}

{% if dc_domain == 'EXAMPLE-CORP.COM' %}
	{% set computer_ou = '--computer-ou=OU=Linux,OU=Servere,DC=ccta,DC=dk' %}
{% endif %}

{% if dc_domain == 'clcta.dk' %}
        {% set computer_ou = '--computer-ou=OU=Linux,OU=Servere,DC=clcta,DC=dk' %}
{% endif %}

{% if dc_domain == 'DMZ23.EXAMPLE.COM' %}
	{% set computer_ou = '--computer-ou=OU=Linux,OU=Servere,DC=dmz23,DC=local' %}
{% endif %}

{% if dc_domain == 'DMZ.EXAMPLE.COM' %}
	{% set computer_ou = '--computer-ou=OU=Linux,OU=Servere,DC=dmz24,DC=local' %}
{% endif %}

spawn realm join {{ "krb5-linux.EXAMPLE-CORP.COM" if dc_domain == "EXAMPLE-CORP.COM" else dc_domain }} {{ computer_ou }} -U {{ ad_join_user }}@{{ dc_domain }}  --verbose

expect "Password for {{ ad_join_user }}@{{ dc_domain}}:" { send -- "{{ ad_join_pass }}\r" }

expect " * Successfully enrolled machine in realm" { send -- "Success" }

exit 0
