Score:0

Unable to login to root after running ansible scripts

eh flag

I am currently not able to login to my super user. Here is the sequence of events

~ su  
password:  
su: using restricted shell which zsh  
su: failed to execute which zsh: No such file or directory  

Previously I was trying to automate with ansible.

- hosts: localhost
  become: true
  tasks: 
  - name: Install zsh
    apt: name=zsh
  - name: change shell
    shell: chsh -s `which zsh`
  - name: Install ohmyzsh autosuggestions plugin
    ansible.builtin.git:
      repo: 'https://github.com/zsh-users/zsh-autosuggestions.git ~/.oh-my-zsh/plugins/zsh-autosuggestions'
      dest: "~/.oh-my-zsh/plugins/zsh-autosuggestions"
  - name: Update our zshrc
    shell: sed -i 's/(git/(git zsh-autosuggestions' ~/.zshrc

When I was running my playbook, sometimes it would fail on the tasks portion

PLAY [localhost] ***************************************************************

TASK [Gathering Facts] *********************************************************
fatal: [localhost]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"failed": true, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}

PLAY RECAP *********************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

and sometimes it gets to the chsh section (I think its when I change my shell or create an alias for python or change the ansible script (get rid of certain steps). I don't fully understand it but it gives me this error for the chsh section

fatal: [localhost]: FAILED! => {"changed": true, "cmd": "chsh -s `which zsh`", "delta": "0:00:00.006789", "end": "2023-08-03 19:46:19.294159", "msg": "non-zero return code", "rc": 1, "start": "2023-08-03 19:46:19.287370", "stderr": "Password: chsh: PAM: Authentication failure", "stderr_lines": ["Password: chsh: PAM: Authentication failure"], "stdout": "", "stdout_lines": []}

Overall there are two things I would like to fix, for one by super user account, but secondly the ansible script so this does not happen again

Archer Heffern avatar
eh flag
Figured out how to fix the issue, although I am not too sure why this issue happened. Turns out I was not able to login to my root user (PAM authentication error) so I ended up using https://askubuntu.com/questions/812420/chsh-always-asking-a-password-and-get-pam-authentication-failure to fix the issue. If anyone knows why this happened or helped please let me know
karel avatar
sa flag
Does this answer your question? [chsh always asking a password , and get \`PAM: Authentication failure\`](https://askubuntu.com/questions/812420/chsh-always-asking-a-password-and-get-pam-authentication-failure)
Score:0
id flag

It seems like which zsh in this ansible task

- name: change shell
    shell: chsh -s `which zsh`

was not evaluated and the default shell was set to which zsh instead of the path to zsh. You set the login shell for root to something that does not exist. When you log in as root, it tries to find a login shell called which zsh, can't find it and gives up.

You could change the task to use a fixed path, something like this:

- name: change shell
    shell: chsh -s /path/to/zsh

If you're running the playbook on different systems where the path to zsh varies, you could read it to a variable in a separate task before running the "change shell" task.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.