0

I'm getting a strange message with Ansible.

On a RHEL 9 server, I can join our domain via the shell command line

realm join example.xyz --user=svc-ansible --computer-ou="OU=Linux Servers, OU=Servers, OU=ACME, OU=Units, DC=example, DC=xyz" 

Once done that I can successfully change user via su - [email protected], where "johndoe" is an user defined in the AD and belonging to an AD group defined in simple_allow_groups in the file /etc/sssd/sssd.conf. So the config seems to be working.

After that, I run an realm leave example.xyz --remove -U 'svc-ansible' and realm list beforehand to check that the server is not in the domain anymore.

However, when I run via AWX an Ansible playbook defined as this

(...) - name: Set staging_ou ansible.builtin.set_fact: staging_ou: "OU=Linux Servers, OU=Servers, OU=ACME, OU=Units, DC=example, DC=xyz" - name: Realm join into domain ansible.builtin.expect: command: /bin/bash -c 'realm join {{ domain }} --user={{ ad_join_user }} --computer-ou="{{ staging_ou }}"' responses: Password.*: "{{ ad_join_password }}" timeout: 120 (...) 

I get the following error:

TASK [playbook_ad_join : Realm join into domain] ********************************** fatal: [myrhel9server]: FAILED! => {"changed": true, "cmd": "/bin/bash -c 'realm join example.xyz --user=svc-ansible --computer-ou="OU=Linux Servers, OU=Servers, OU=ACME, OU=Units, DC=example, DC=xyz"'", "delta": "0:00:00.152467", "end": "2024-11-13 11:45:09.577079", "msg": "non-zero return code", "rc": 1, "start": "2024-11-13 11:45:09.424612", "stdout": "realm: Already joined to this domain\r\nPlease check\r\n https://red.ht/support_rhel_ad \r\nto get help for common issues.", "stdout_lines": ["realm: Already joined to this domain", "Please check", " https://red.ht/support_rhel_ad ", "to get help for common issues."]}

A realm list confirms that the server is indeed in the example.xyz domain and returns the same output as when I ran the realm join ... command via shell. However, I cannot su to AD users anymore: trying to do so returns an error

su: user [email protected] does not exist or the user entry does not contain all the required fields

The link cited in the error message doesn't help.

What could be wrong?


EDIT 1: Running via shell the same command run via ansible, i.e.

/bin/bash -c 'realm join example.xyz (...) ' 

doesn't change anything with respect to running realm join example.xyz (...) (see top of post).

The other tasks in the playbook only modify a few config files:

/etc/krb5.conf /etc/sssd/sssd.conf /usr/local/bin/sss_ssh_authorizedkeys_ad /etc/ssh/sshd_config 

and install some packages. These do not matter as the configuration already converged. I have removed a line which restarted the realmd daemon, since it could be the one causing the issue, but nothing changed.

4
  • 2
    Two questions: (a) what happens when you type the same command being invoked by Ansible? I.e., the full /bin/bash -c ..... and (b) what happens when you run a playbook that has only the two tasks you posted in this question, and nothing else? (i.e., a simulation of what you type manually) Commented Nov 13, 2024 at 11:45
  • Thanks for your questions. I have answered them in the post. Commented Nov 13, 2024 at 13:15
  • Maybe the commands don't run as the same user? You could add the realm list command to a task right before the Realm join into domain task. Commented Nov 13, 2024 at 17:18
  • 2
    @dr_ that's good, but I asked what happens when you invoke a playbook containing just the two tasks you posted in the question. It's not a thought experiment that can be satisfied by saying "the previous tasks don't matter", but a real experiment that must be performed to see the results. Based on my own experience troubleshooting similar Ansible problems, it's necessary to actually perform the test. Commented Nov 13, 2024 at 18:24

1 Answer 1

0

I managed to pinpoint the problem by removing as many tasks as possible (as suggested by @SottoVoce in the comments). Eventually the playbook worked via a kludge -- by adding a realm leave task (with ignore_errors: true) just before the realm join task.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.