Joining Linux server to the Active directory Domain.

Fahad Riaz <fahad.riaz1718@gmail.com>

3:50 PM (4 minutes ago)


to ansible-project

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

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

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

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

   - name: join system to ad
     expect:
       command: realm join -U ansibleuser addomain.com
       responses:
         Password for ansibleuser: "{{ domain_password }}"

Hey Steve, Thank you so much, You’re a life saver, the shell: echo “{{ domain_password }}” | realm join -U ansibleuser addomain.com 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