ali haider
ali haider

Reputation: 20202

stopping a service using ansible

I am using ansible to test against a VM where I have already installed nginx. I tried stopping the service using the command below and the resulting status displays that the process stopped. However, on tha target server, I can see that the process is still running (and has been running for a few days). I have the correct server in the ansible command and am checking the right server. Any thoughts on why the command would display the status that the service has stopped even when it does not seem to have done so.

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"
}

Upvotes: 4

Views: 16030

Answers (1)

G.shivaji
G.shivaji

Reputation: 27

in play-book:

- name: stop nginx service 
  service: name=nginx state=stopped 

or

adhoc-command:to stop service

ansible testserver -m service -a "name=nginx state=stopped"

Upvotes: 2

Related Questions