gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 09:57:52 26 4
gpt4 key购买 nike

我可以在远程 linux 上运行正常的 uptime 命令。但是需要 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]

最佳答案

Q: " I am a normal user@test and have to "sudo su -" to be a root on remote "test" to do dmidecode "

问题是 root@test “找不到 dmidecode 命令”

/bin/sh: dmidecode: command not foundnon-zero return code

答:看看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 并找出问题所在。

关于linux - 想通过 ansible 运行简单的 root 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58712622/

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