2
- name: Add targeted machine to domain
  become_user: <local user>
  expect:
   command: /bin/bash -c "/usr/sbin/realm join --user={{ prompted_user }}@domain.com domain.com
   responses:
     Password for .*: "{{ prompted_pass }}"

fatal: [<host-ip>]: FAILED => {
     "changed":true,
     "cmd": "bin/bash -c \"/usr/sbin/realm join --user=promted_user@domain.com domain.com\"",
     "delta": "0:00:00.459430"
     "end"; "<date_time>"
     "invocation" : {
         "module_args": {
             "chdir": null,
             "command": "bin/bash -c \"/usr/sbin/realm join --user=promted_user@domain.com domain.com\"",
             "creates": null,
             "echo": false
             "removes": null,
             "responses" : { 
                 "Password for .*": "<prompted_pass>"
             },
             "timeout": 30
        }
},
"msg": "non-zero return code",
"rc": 1,
"start": "<data_time>"
"stdout": "Password for prompted_user@domain.com: \r\nrealm: Couldn't join realm: Not authorized to perform this action:,
"stdout_lines": [
    "Password for prompted_user@domain.com: ",
    "realm: Couldn't join realm: Not authorized to perform this action"
    ]
}

The top is the task and the bottom is the output. I don't know why its not passing the password or, if it is I don't know why its not running sudo when I do these actions traditionally without ansible it works just fine. Defiantly need help.

Thank you

  • wow this thing butchered my error to being barely readable... thanks – Zachary Walker Sep 28 '20 at 22:51
  • There are a whole bunch of formatting buttons available when you post, if you don't use them that's on you. I selected all the ansible output and clicked the curly braces (Code Sample). –  Sep 29 '20 at 00:22
  • sure iv never used this forum to post just figured it would take my self imposed formatting, either way 99% of all problems orginate between the chair and the screen, it seems to have figured out the formatting which is nice.. edit: OH I see you helped me out thank you – Zachary Walker Sep 29 '20 at 14:05

1 Answers1

3

Assuming the prompted_user and prompted_pass variables are filled elsewhere, it looks like become: yes is missing, and become_user: should be root.

- name: Add targeted machine to domain
  become_user: root
  become: yes
  expect:
   command: /bin/bash -c "/usr/sbin/realm join --user={{ prompted_user }}@domain.com domain.com
   responses:
     Password for .*: "{{ prompted_pass }}"

Note: if you have become_user: root and become_method: sudo in the /etc/ansible/ansible.cfg or in an ansible.config file within your role, or you have applied them at the commandline, or at the playbook or role level, you do not need to apply these at the task level.

Jeter-work
  • 845
  • 4
  • 15
  • I've just spent an entire day trying to deal with the error and discovered `sudo` was the answer, feel like a right chump! I don't know Ansible but the error message is definitely a local privilege issue rather than the remote server. – Oly Dungey Mar 30 '21 at 16:55