Edit current user’s shell with ansible

I’m trying yo push my dot files and some personal configuration files to a server (I’m not root or sudoer). Ansible connects as my user in order to edit files in my home folder.

I’d like to set my default shell to usr/bin/fish. I am not allowed to edit /etc/passwd so

  name: shaka
  shell: /usr/bin/fish

won’t run.

I also checked the chsh command but the executable prompt for my password.

How could I change my shell on such machines ? (Debian 8, Ubuntu 16, Opensuse)


I ended up using two ansible modules :

  • ansible expect
  • ansible prompt

First I record my password with a prompt :

  - name: "my_password"
    prompt: "Enter password"
    private: yes

And then I use the module expect to send the password to the chsh command :

  - name: Case insensitve password string match
      command: "chsh -s /usr/bin/fish"
        (?i)password: "{{ my_password }}"
      creates: ".shell_is_fish"

The creates sets a lock file avoiding this task to be triggered again. This may be dangerous because the shell could be changed after and ansible will not update it (because of the lock still present). You may want to avoid this behaviour.