Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to define login user and become root in playbook

Tags:

ansible

my loginuser is user1 and i want to execute the playbook with root. how can i do this. if i use in cmdline it does not work like this

ansible-playbook main.yaml -i hosts --user=git -k --become-user=root --ask-become-pass --become-method=su

Please tell me how to implement this.

name: Install and Configure IEM
hosts: rhel
ansible_become: yes
ansible_become_method: su
ansible_become_user: root
ansible_become_pass: passw0rd
tasks:
 
 - name: Creating masthead file path
   file: path=/etc/opt/BESClient state=directory
   
 - name: Creating install directory
like image 434
shamim Avatar asked Dec 28 '15 10:12

shamim


People also ask

How do you pass the root password in Ansible playbook?

Providing the sudo Password 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.

What is become yes in Ansible playbook?

Adding become: yes and become_method: enable instructs Ansible to enter enable mode before executing the task, play, or playbook where those parameters are set.


1 Answers

I use :

deploy.yml

- name: Todo something
  hosts: all
  become: yes
  become_user: root
  become_method: su

When you execute the playbook pass the password as an extra var.

 --extra-vars='ansible_become_pass=password'
like image 69
Raul Hugo Avatar answered Sep 18 '22 11:09

Raul Hugo