0

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

1 Answers1

0

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.