Realm command - join domain after building CentOS VM via template

Problem: I am building CentOS 7 VM’s successfully using a template. I would like to join the host to our domain after the build is complete. My code to do this is below, but it is failing. Several questions: does anyone have a snippet to do this or an easier way? Is there a way in the template to get a return code from the command? I am new to Foreman, so be gentle.

Code:

<% if realm_compatible && host_enc['parameters']['realm'] && host.realm && @host.realm.realm_type== 'Active Directory' -%>
logger "trying to join host"          ## I see this in my logs, so the above line must be returning true
realm join --one-time-password='<%= @host.otp || "$HOST[OTP]" %>' <%= @host.realm %>
<% end -%>

Foreman and Proxy versions: 1.18.1

Foreman and Proxy plugin versions: