Realm在RHEL 7.9上从Ansible运行失败



我正在尝试使用Ansible自动加入Linux服务器到AD域。除了实际的连接之外,我几乎让所有的东西都工作了。因为这是RHEL7, Ansible模块ansible.builtin.expect不起作用,因为RHEL7只有预期2.6,而Ansible预计它是3.3或更高。在到处寻找之后,我发现使用Linux expect:

shell: |
set timeout 300
spawn /usr/sbin/realm join -v --user=Administrator --computer-ou="OU=Linux,OU=Servers," --os-name={{ ansible_distribution }} --os-version={{ ansible_distribution_version }} my.domain.com
expect "Password for * "
send "{{ bind_password }}"
expect "* Successfully enrolled machine in realm"
send "n"
exit 0
args:
executable: /usr/bin/expect
when: realmd_bound.failed

这与"realm: Specify one realm to join"失败,即使我在一个领域。我尝试从测试目标执行命令,命令执行正确。

Ansible做的与常规命令行不同的是什么,我如何纠正它?

编辑:

我试着把领域发现与领域加入一致

realm discover my.domain.com && realm join --user=admin@my.domain.com --computer-ou="OU=Linux,OU=Servers," --os-name={{ ansible_distribution }} --os-version={{ ansible_distribution_version }} my.domain.com

现在我得到:

"realm: Unknown option --user=admin@my.domain.com"

更多的故障排除:

我试过这个脚本。但是我得到了同样的错误。经过进一步的研究,我发现这很有帮助。我输入了他们被建议去的地方,我在一个新的地方停了下来。我们的管理员帐户有一个"$"在他们。在我被一大堆"这是Linux!"永远不要在名字中使用$ !$是特别的!!"我知道,但这是一个Windows商店,早在Linux开始悄悄进入之前。而且,正如你所知道的,Windows几乎没有什么东西是特别的。

话虽如此,我现在得到了&;can't read &;amp&;; no such variable&;。admin id以$amp结尾,因此它不能读取变量$amp。当我使用调查输入用户ID时,我使用$组合,并将用户$amp作为命令发送。然后Realm将其解释为用户(变量的值)。我试过$,所以它会在命令中输入$,但它所做的只是输入\$,它仍然没有运行。

我无法避免使用$.

如果我需要把这一部分单独放在一个问题中,请告诉我。

Q:">如何发现脚本中的错误。由于没有返回错误描述。">

A:字典ansible_failed_result在失败的block/rescue中总是可用的,例如

- hosts: localhost
tasks:
- block:
- shell: /usr/bin/false
rescue:
- debug:
var: ansible_failed_result

TASK [shell] ***************************************************************
fatal: [localhost]: FAILED! => changed=true 
cmd: /usr/bin/false
delta: '0:00:00.004537'
end: '2021-08-15 14:23:20.533469'
msg: non-zero return code
rc: 1
start: '2021-08-15 14:23:20.528932'
stderr: ''
stderr_lines: <omitted>
stdout: ''
stdout_lines: <omitted>
TASK [debug] ***************************************************************
ok: [localhost] => 
ansible_failed_result:
changed: true
cmd: /usr/bin/false
delta: '0:00:00.004537'
end: '2021-08-15 14:23:20.533469'
failed: true
invocation:
module_args:
_raw_params: /usr/bin/false
_uses_shell: true
argv: null
chdir: null
creates: null
executable: null
removes: null
stdin: null
stdin_add_newline: true
strip_empty_ends: true
warn: true
msg: non-zero return code
rc: 1
start: '2021-08-15 14:23:20.528932'
stderr: ''
stderr_lines: []
stdout: ''
stdout_lines: []

最新更新