Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use --ask-become-pass with ansible 1.9.4

I am a new user to ansible. I am attempting to use the privilege escalation feature to append a line to a file owned by root.

The following documentation tells me I can use --ask-become-pass with become_user to be prompted for the become_user password but I have no idea how to use it.

http://docs.ansible.com/ansible/become.html

My current code I am working with is as follows:

- name: Add deploy to sudoers
        remote_user: me
        become: yes
        become_method: su
        ask_become_pass: true
        lineinfile:
          dest=/etc/somefile
          line=sometext
          regexp="^sometext"
          owner=root
          state=present
          insertafter=EOF
          create=True

Which gives me the error: ERROR: ask_become_pass is not a legal parameter in an Ansible task or handler

Can anyone give me an idea of what I might be doing wrong here?

Thanks in advance.

like image 541
Vell Avatar asked Oct 27 '15 14:10

Vell


People also ask

What is the use of become in Ansible?

Ansible allows you to 'become' another user, different from the user that logged into the machine (remote user). This is done using existing privilege escalation tools, which you probably already use or have configured, like sudo , su , pfexec , doas , pbrun , dzdo , ksu and others.

What is -- ask become pass?

If the remote user needs to provide a password in order to run sudo commands, you can include the option --ask-become-pass to your Ansible command. This will prompt you to provide the remote user sudo password: ansible all -m ping --ask-become-pass.

How do I specify sudo password in Ansible?

You can pass variable on the command line via --extra-vars "name=value". You need to use the Sudo password variable named ansible_sudo_pass as shown below.


1 Answers

The doc says that ask_become_pass is a command line parameter. Which means you have to use it while executing the playbook:

ansible-playbook *playbook-name* --ask-become-pass
In this case ansible will ask for the password.

The other option ansible_become_pass can be used in the inventory or also as an extra_var. There you can set the password while executing the playbook.

like image 158
Capri90 Avatar answered Oct 07 '22 12:10

Capri90