using the new "become" syntax, how do you configure your playbook to log in to a host as a regular user, switch to the root user and ask for a password?

I tried:

- hosts: foo
  gather_facts: no
  remote_user: martin
  become: yes
  become_method: su

  - name: update
    yum: name=tree state=latest

This playbook just hands in the TASK phase. I also tried removing the become_method and using ansible-playbook book.yml --ask-become-pass but that also didn't work. Any ideas?

  • did you try to use sudo?
    – Jakuje
    Feb 9 '16 at 16:17
  • @Jakuje I know how to make it work with sudo and su but I'm looking for how to do this with the become directives. I do not use sudo on the target machine, only a plain root account.
    – mart1n
    Feb 9 '16 at 19:34
  • Please post the error message otherwise it is not possible to tell what is going wrong. Is the user martin able to use the su command? Feb 10 '16 at 8:33
  • 1
    So sudo: yes is working but become: yes is not? But @Jakuje has a point, with "did you try sudo?" - not as sudo: yes but as become_method: sudo (which is the default if omitted)
    – udondan
    Feb 12 '16 at 3:28
  • 1
    I believe if you set become_method: su you need to provide root password with --ask-become-pass as Ansible will login with remote_user and gain privilege with su. Maybe adding become_user: root will solve your problem. Feb 12 '16 at 10:10

I think I hit something similar to this recently and ended up putting these lines in ansible.cfg:


I think the become_user directive is unnecessary as thats also the default, but I think it was the become_ask_pass that made the difference and stopped it hanging.

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.