我的ansible命令不会在php中使用shell_exec函数运行,但是另一个 像ls,pwd之类的命令可以正常工作,请注意,我的php代码托管在nginx Web服务器上 并且我以本地用户和远程服务器的“用户”身份登录到了具有此名称“ dockerengine”的远程服务器上
<%php
shell_exec("ansible dockerengine -m shell -a 'echo hello > /home/user/hello.txt'")
%>
当我在终端中执行命令ansible dockerengine ...(dockerengine是我的远程服务器)时,它运行正常
还请注意,我在远程服务器上将ssh密钥和sudoers文件配置为自动升级特权
//this code contained in a file with root priv hosted on nginx
<%php shell_exec("ansible dockerengine -m shell -a 'echo hello > /home/user/hello.txt'") %>
// this line is written in the sudoers file of my remote server (dockerengine)
user ALL=(ALL) NOPASSWD:ALL
// this line is written in the /etc/ansible/hosts file in my local machine
[docker]
dockerengine ansible_user=user