Getting Error "You need to be root to perform this command" ansible-playbook
13,589
Same error, you should include become and become_user. In some cases add become method. More
- hosts: somehost
name: Install something
become: yes
remote_user: yourname
become
set to yes to activate privilege escalation.
become_user
set to user with desired privileges — the user you become, NOT the user you login as. Does NOT imply become: yes, to allow it to be set at host level. Default value is root.
Related videos on Youtube
Author by
Sanjay Sethi
Updated on June 04, 2022Comments
-
Sanjay Sethi over 1 year
I am running below playbook. which will login to the server using ec2-user but mysql-java-connector will be installed, my test1 user.
--- - hosts: cluster become: yes remote_user: ec2-user tasks: - name: Create test1 User user: name: test1 password: '$6$jQX0JQzf8GB$NI/Pv1rMLyxWYaFCGNsbrun3sfn5bXSzg89Ip.ga2yf3n7hhrjiPsEo5IChIA7X8xVxnuZzm2sWA7IRM6qZOR0' state: present shell: /bin/bash # Defaults to /bin/bash system: no # Defaults to no createhome: yes # Defaults to yes home: /home/test1 - name: Add users to sudoers lineinfile: dest : /etc/sudoers state: present line: 'test1 ALL=(ALL) NOPASSWD: ALL' - name: Install mysql java connector become_user: test1 become_method: sudo yum: name=mysql-connector-java state=present
Gets below error:
fatal: [xxx.xxx.xxx.211]: FAILED! => {"changed": false, "msg": "You need to be root to perform this command.\n", "rc": 1, "results": [""]}
-
Sanjay Sethi about 5 yearsi want to install with test1 user which is having sudo permission. If i use become_user: root mean i am installing it through root user. same way like most user install and run apache with apache user instead of root.
-
Alexey Vazhnov about 5 yearsIf only
test
user have fullsudo
permission, then useremote_user: test
instead ofremote_user: ec2-user
. Anyway,yum
works fromroot
user only. To run your service from non-root, you should reconfigure your service after installation. But there are no service start in your example, only installation. Installation withyum
works only fromroot
user. -
Abdelghani Roussi over 3 yearsfor more informations, please visit : Ansible docs : become