在ansible中获得root权限 [英] Getting root privileges in ansible
问题描述
我在 ansible 中有以下任务:
I have the following task in ansible:
- file: "state=directory path=/servers/repo"
sudo: yes
name: "Create the base site directory."
它应该以我的用户身份运行,但具有 root 权限.但即使我的用户是一个 sudoer 它也失败了
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
当然,当我在服务器中执行 sudo -s
时,我拥有所有正确的权限,但不知何故,它无法正常工作.
Of course, when i do sudo -s
in the server i have all the right permissions but somehow with ansible it's not working.
知道为什么吗?
推荐答案
问题是我没有权限运行/bin/sh.我需要将可执行文件设置为/bin/bash - 这可以在 ansible 的配置文件中完成.所以在当前目录中,我创建了 ansible.cfg 文件,内容如下:
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
就是这样!
这篇关于在ansible中获得root权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!