Getting root privileges in ansible

旧巷老猫 提交于 2019-12-07 07:43:17

问题


I have the following task in ansible:

- file: "state=directory path=/servers/repo"
  sudo: yes
  name: "Create the base site directory."

which should run as my user but with root privileges. But even though my user is a sudoer it fails with

Sorry, user sofiab is not allowed to execute '/bin/sh -c echo SUDO-SUCCESS-amlzcqzchzpjsgkllckjhjfednpjgevj; LANG=C LC_CTYPE=C /usr/bin/python /home/sofiab/.ansible/tmp/ansible-tmp-1409321488.66-202796192861545/file; rm -rf /home/sofiab/.ansible/tmp/ansible-tmp-1409321488.66-202796192861545/ >/dev/null 2>&1' as root

Of course, when i do sudo -s in the server i have all the right permissions but somehow with ansible it's not working.

Any idea why?


回答1:


The problem was that i had no permission to run /bin/sh. I needed to set the executable to /bin/bash - this can be done in ansible's config file. So in the current directory i created the ansible.cfg file with the following contents:

executable = /bin/bash

and that was it!




回答2:


It seems like you do not have full sudo access, because of which some commands are failing with Ansible. Can you try running the below commands with sudo and see if you can successfully execute it on your remote host ?

/bin/sh
echo
/usr/bin/python
rm

If any of that doesn't works then you should add that command to your sudoers file.



来源:https://stackoverflow.com/questions/25570202/getting-root-privileges-in-ansible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!