How to identify the login user and become root in the playbook

my loginuser is user1 and I want to run the playbook with root. How can i do this. if i use in cmdline, this does not work.

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 
+5
source share
2 answers

I use:

deploy.yml

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

When you are playing back, pass the password as an optional var.

  --extra-vars='ansible_become_pass=password' 
+16
source

From Unrelated Documents :

  • you can set them in the playbook as @ Raul-Hugo, with become_user and become_user ;
  • alternatively, this can also be done in an inventory that allows you to install on a host or group. But then the variables get the prefix "ansible_": ansible_become_user , ansible_become_user , etc. That the game you gave in your question did not work: it used the names of the variables that are used in the inventory.
+2
source

Source: https://habr.com/ru/post/1239346/


All Articles