I am trying to use Ansible with the expect module to join a linux server to a active directory with sssd.

code from the task:

- name: join domain
    command: /bin/bash -c "/usr/sbin/realm join --user=join-user domain.loc"
       password: "secret"

I got the code from this link since I googled around before asking here: https://groups.google.com/forum/#!msg/ansible-project/L0Es3aGAKV8/DmPRaiGcBwAJ

The actual problem is that Ansible does not seem to actually respond to the prompt. Because when I run the playbook it just times out. I did test this directly via ssh and it works. Credentials are fine and the connection to the domain controller works.

Output of the playbook when it times out:

fatal: []: FAILED! => {
    "changed": true, 
    "cmd": "/bin/bash -c \"/usr/sbin/realm join --user=join-user domain.loc\"", 
    "delta": "0:00:30.112149", 
    "end": "2017-03-22 08:37:18.320832", 
    "failed": true, 
    "invocation": {
        "module_args": {
            "chdir": null, 
            "command": "/bin/bash -c \"/usr/sbin/realm join --user=join-user domain.loc\"", 
            "creates": null, 
            "echo": false, 
            "removes": null, 
            "responses": {
                "password": "secret"
            "timeout": 30
        "module_name": "expect"
    "msg": "command exceeded timeout", 
    "rc": null, 
    "start": "2017-03-22 08:36:48.208683", 
    "stdout": "Password for join-user: ", 
    "stdout_lines": [
        "Password for join-user: "

Any help is greatly appreciated.


response must match the stdout string, or you can use regex, in your case you can use:

  Password for join-user: "secret"


  Password for .*: "secret"

from doc

The question, or key, under responses is a python regex match. Case insensitive searches are indicated with a prefix of ?i

  • Well, that was a quick and perfect response. This solved my problem it seems. Thanks for that. I will do a little more testing and mark this as the answer if I can fully confirm. Should the read the docs better... – SomeGuyOnTheNet Mar 22 '17 at 8:00
  • Hm...seems like we go into the right direction, but not completely. The new error says: "realm: Couldn't join realm: Not authorized to perform this action". This is strange as the command perfectly works directly via ssh. I double checked the credentials again and they are right. – SomeGuyOnTheNet Mar 22 '17 at 8:34
  • maybe removes " around secret? I'm not sure about handling this inside ansible – Quantim Mar 22 '17 at 8:58
  • Already tried that, but it does not help. But thanks for the first hint ;) – SomeGuyOnTheNet Mar 22 '17 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.