# Joining Linux server to the Active directory Domain.

**URL:** <https://forum.ansible.com/t/joining-linux-server-to-the-active-directory-domain/28893>\
**Category:** Ansible Project\
**Created:** [October 29, 2018, 8:56pm UTC](https://forum.ansible.com/t/joining-linux-server-to-the-active-directory-domain/28893 "2018-10-29T20:56:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fahad.riaz1718](https://avatars.discourse-cdn.com/v4/letter/f/7993a0/32.png) [@fahad.riaz1718](https://forum.ansible.com/u/fahad.riaz1718)\
**Post date:** [October 29, 2018, 8:56pm UTC](https://forum.ansible.com/t/joining-linux-server-to-the-active-directory-domain/28893/1 "2018-10-29T20:56:02Z")

</div>

| 
### Fahad Riaz \<fahad.riaz1718@gmail.com\>
 |

3:50 PM (4 minutes ago)

![](https://us1.discourse-cdn.com/ansible/original/2X/5/56d45f8a17f5078a20af9962c992ca4678450765.gif)  
 ![](https://us1.discourse-cdn.com/ansible/original/2X/5/56d45f8a17f5078a20af9962c992ca4678450765.gif)

| 

to ansible-project  
 ![](https://us1.discourse-cdn.com/ansible/original/2X/5/56d45f8a17f5078a20af9962c992ca4678450765.gif)

 |

I am working on a project and part of it includes joining the Linux server to the Active Directory domain.

I’ve tried every possible way to join the server to the AD but can’t resolve it.  
This is the playbook I try to run

---

<div class="post-metadata">

**Author:** ![S\_C\_Rigler](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@S\_C\_Rigler](https://forum.ansible.com/u/S_C_Rigler)\
**Post date:** [October 29, 2018, 9:12pm UTC](https://forum.ansible.com/t/joining-linux-server-to-the-active-directory-domain/28893/2 "2018-10-29T21:12:03Z")

</div>

Hi Fahad,

You could probably get away with changing your task to do something like:

- name: join system to ad  
shell: echo “{{ domain\_password }}” | realm join -U ansibleuser [addomain.com](http://addomain.com)

But it’s generally bad practice to put passwords on the command line, since anyone logged onto the target machine could just do “ps” and see the password exposed.

Another option would be to create a keytab for “ansibleuser” then have the playbook kinit the service account using the keytab and do an unattended join. But you’d have to make sure that everything is cleaned up (keytab and the associated ticket cache) after the join is complete.

Neither of these are idempotent, however. So every time you run the playbook it will just be trying to do the join again no matter the status of the machine.

– Steve

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 29, 2018, 9:35pm UTC](https://forum.ansible.com/t/joining-linux-server-to-the-active-directory-domain/28893/3 "2018-10-29T21:35:48Z")

</div>

It looks like you are trying to use the expect module, but missing the module name.  
It should be written like this:

&nbsp;&nbsp;&nbsp;- name: join system to ad  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expect:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: realm join -U ansibleuser addomain.com  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;responses:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Password for ansibleuser: "{{ domain\_password }}"

---

<div class="post-metadata">

**Author:** ![fahad.riaz1718](https://avatars.discourse-cdn.com/v4/letter/f/7993a0/32.png) [@fahad.riaz1718](https://forum.ansible.com/u/fahad.riaz1718)\
**Post date:** [October 30, 2018, 1:42pm UTC](https://forum.ansible.com/t/joining-linux-server-to-the-active-directory-domain/28893/4 "2018-10-30T13:42:53Z")

</div>

Hey Steve, Thank you so much, You’re a life saver, the shell: echo “{{ domain\_password }}” | realm join -U ansibleuser [addomain.com](http://www.google.com/url?q=http%3A%2F%2Faddomain.com&sa=D&sntz=1&usg=AFQjCNFliqfO7XMaA0lb3UCCdPJwvgjXZw) seemed to work perfectly fine. once again thank you very much Steve.

and Kai I tried the expect module and it promoted me to install pexpect module 3.3 which is currently not recommended by Red Hat and my company doesn’t want to have pexpect 3.3 therefore i needed another way around.

Thank you once again

Best.  
Fahad Riaz
