我正在使用ansible来测试我已经安装了nginx的VM。我尝试使用下面的命令停止服务,结果状态显示进程已停止。但是,在目标服务器上,我可以看到该进程仍在运行(并且已运行了几天)。我在ansible命令中有正确的服务器 我正在检查正确的服务器。有关为什么命令将显示服务已停止的状态的任何想法,即使它似乎没有这样做。
ansible testserver -vvv -m service -a "name=nginx state=stopped"
Using /home/test/devops/ansible.cfg as config file
<ec2-xx.xxx.xxx.xxx.compute-1.amazonaws.com> ESTABLISH SSH CONNECTION FOR USER: test
<ec2-xx.xxx.xxx.xxx.compute-1.amazonaws.com> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o Port=1234 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=test -o ConnectTimeout=10 -o ControlPath=/home/test/.ansible/cp/ansible-ssh-%h-%p-%r ec2-xx.xxx.xxx.xxx.compute-1.amazonaws.com '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1467905869.39-108785461246651 `" && echo ansible-tmp-1467905869.39-108785461246651="` echo $HOME/.ansible/tmp/ansible-tmp-1467905869.39-108785461246651 `" ) && sleep 0'"'"''
<ec2-xx.xxx.xxx.xxx.compute-1.amazonaws.com> PUT /tmp/tmpqpCm5g TO /home/ali/.ansible/tmp/ansible-tmp-1467905869.39-108785461246651/service
<ec2-xx.xxx.xxx.xxx.compute-1.amazonaws.com> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o Port=1234 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ali -o ConnectTimeout=10 -o ControlPath=/home/test/.ansible/cp/ansible-ssh-%h-%p-%r '[ec2-52-87-166-241.compute-1.amazonaws.com]'
<ec2-xx.xxx.xxx.xxx.compute-1.amazonaws.com> ESTABLISH SSH CONNECTION FOR USER: test
<ec2-xx.xxx.xxx.xxx.compute-1.amazonaws.com> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o Port=1234 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ali -o ConnectTimeout=10 -o ControlPath=/home/ali/.ansible/cp/ansible-ssh-%h-%p-%r -tt ec2-xx.xxx.xxx.xxx.compute-1.amazonaws.com '/bin/sh -c '"'"'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/test/.ansible/tmp/ansible-tmp-1467905869.39-108785461246651/service; rm -rf "/home/test/.ansible/tmp/ansible-tmp-1467905869.39-108785461246651/" > /dev/null 2>&1 && sleep 0'"'"''
testserver | SUCCESS => {
"changed": true,
"invocation": {
"module_args": {
"arguments": "",
"enabled": null,
"name": "nginx",
"pattern": null,
"runlevel": "default",
"sleep": null,
"state": "stopped"
},
"module_name": "service"
},
"name": "nginx",
"state": "stopped"
}
答案 0 :(得分:2)
在剧本中:
- name: stop nginx service
service: name=nginx state=stopped
或
adhoc-command:停止服务
ansible testserver -m service -a "name=nginx state=stopped"