0

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
  expect:
    command: /bin/bash -c "/usr/sbin/realm join --user=join-user domain.loc"
    response:
       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: [192.168.11.1]: 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.

SomeGuyOnTheNet
  • 33
  • 1
  • 2
  • 7

1 Answers1

3

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

response:
  Password for join-user: "secret"

or

response:
  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

Quantim
  • 1,269
  • 11
  • 13
  • 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 08: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 08:34
  • maybe removes `"` around `secret`? I'm not sure about handling this inside ansible – Quantim Mar 22 '17 at 08:58
  • Already tried that, but it does not help. But thanks for the first hint ;) – SomeGuyOnTheNet Mar 22 '17 at 09:05