gpt4 book ai didi

linux - Ansible sudo 不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:37:03 27 4
gpt4 key购买 nike

我正在编写 Ansible 脚本以在 CentOS 机器上安装一些软件包。

我无法使用 sudo 在 Ansible 中执行简单的 YUM 命令

- name: Install Java
yum: name={{java_version}} state=present
sudo_user: dexter
sudo: yes

出现以下错误

TASK: [tomcat | Install Java] ************************************************* failed: [server-name] => {"changed": true, "rc": 1, "results": ["Loaded plugins: fastestmirror, la ngpacks\n"]} msg: You need to be root to perform this command. FATAL: all hosts have already failed -- aborting

我还设置了我的远程用户。

remote_user: dexter

我正在使用 ansible 1.7.2

我只能访问 dexter 用户(不能访问 root)

dexter 用户在 sudoers 列表中。

我可以在机器上对用户执行 sudo 命令,也可以执行类似的操作

sudo yum install ...

很奇怪,我还可以使用 shell 在 Ansible 中运行 SUDO 命令

- name: Add permissions to dummy path
shell: sudo chmod 0755 {{dummy_path}}

ansible 中的 sudo 似乎与 sudo 命令不同。还是我做错了什么?

谢谢!

[EDIT] 根据@tedder42 的建议,我在控制台输出中添加了不带 sudo_user 的 (-vvvv'),但使用了 sudo: yes

TASK: [apache | Install Apache] ***********************************************

<server-name> ESTABLISH CONNECTION FOR USER: dexter

<server-name> REMOTE_MODULE yum name=httpd state=present

<server-name> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=dexter', '-o','ConnectTimeout=10', 'server-name', "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1416243654.43-120840990326663 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1416243654.43-120840990326663 && echo $HOME/.ansible/tmp/ansible-tmp-1416243654.43-120840990326663'"]

<server-name> PUT /tmp/tmpV8bobo TO /home/dexter/.ansible/tmp/ansible-tmp-1416243654.43-120840990326663/yum

<server-name> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=dexter', '-o', 'ConnectTimeout=10', 'server-name', u'/bin/sh -c \'sudo -k && sudo -H -S -p "[sudo via ansible, key=nnqylcywghyrogwhmdyzwidpsqbqxuef] password: " -u root /bin/sh -c \'"\'"\'echo SUDO-SUCCESS-nnqylcywghyrogwhmdyzwidpsqbqxuef; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python -tt /home/dexter/.ansible/tmp/ansible-tmp-1416243654.43-120840990326663/yum; rm -rf /home/dexter/.ansible/tmp/ansible-tmp-1416243654.43-120840990326663/ >/dev/null 2>&1\'"\'"\'\'']

fatal: [server-name] => failed to parse: Sorry, user dexter is not allowed to execute '/bin/sh -c echo SUDO-SUCCESS-nnqylcywghyrogwhmdyzwidpsqbqxuef; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python -tt /home/dexter/.ansible/tmp/ansible-tmp-1416243654.43-120840990326663/yum; rm -rf /home/dexter/.ansible/tmp/ansible-tmp-1416243654.43-120840990326663/ >/dev/null 2>&1' as root on server-name.mia.amadeus.net.


FATAL: all hosts have already failed -- aborting

最佳答案

你不需要线:

sudo_user: dexter 

它导致脚本以“dexter”身份执行,而你想成为 root。所以 ansible ssh 到远程主机作为用户 'dexter',然后 sudo 到 'dexter'。 :)

http://docs.ansible.com/playbooks_intro.html

关于linux - Ansible sudo 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26935810/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com