想通过ansible运行简单的root命令

我可以在远程Linux上运行正常的正常运行时间命令。 但是需要root特权的命令出错。 这是怎么了通常,我必须登录远程linux并输入“ sudo su-”,然后发出dmidecode命令。

[root@automation ansible]# ansible test -m shell -a "dmidecode" -c paramiko -k -b
test101.com | FAILED | rc=127 >>
/bin/sh: dmidecode: command not foundnon-zero return code




[root@automation ansible]# ansible test -m shell -a "uptime" -c paramiko -k
SSH password:
test101.com | CHANGED | rc=0 >>
 21:34:38 up 284 days,8:24,2 users,load average: 0.32,0.31,0.35
[root@automation ansible]# cat ansible.cfg
[defaults]
inventory       = /etc/ansible/hosts
host_key_checking = false
remote_tmp     = $HOME/.ansible/tmp
pattern        = *
forks          = 10
poll_interval  = 15
ask_pass=True
sudo_user      = root
#user           = test
remote_user = test
transport      = smart
#module_lang    = C
gathering = smart
fact_caching = redis
sudo_exe = sudo
timeout = 15
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}
deprecation_warnings=False
fact_caching = memory
log_path=/etc/ansible/logfile
command_warnings=False
[paramiko_connection]
[ssh_connection]
[accelerate]
o919977230 回答:想通过ansible运行简单的root命令

  

Q:”我是一个普通的user @ test,必须以“ sudo su-”作为远程“ test”的根目录才能执行dmidecode“

问题是root @ test无法找到“ dmidecode命令”。

  

/ bin / sh:dmidecode:找不到命令非零返回码

A:看一下 PATH 是什么, dmidecode

在哪里
[root@automation ansible]# ansible test -m command -a "echo $PATH" -c paramiko -k -b
[root@automation ansible]# ansible test -m command -a "which dmidecode" -c paramiko -k -b

您可能要登录到 root @ test 并找出问题所在。

,

提供dmidecode的路径,并在参数中提供。

ansible test -m shell -a "/path of the file/dmidecode" -c paramiko -k -b --become -u test --ask-become-pass
本文链接:https://www.f2er.com/3159162.html

大家都在问