{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/4024","repository_url":"https://api.github.com/repos/ansible/ansible-modules-core","labels_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/4024/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/4024/comments","events_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/4024/events","html_url":"https://github.com/ansible/ansible-modules-core/issues/4024","id":161978139,"number":4024,"title":"Service module fails when remote host is a docker container","user":{"login":"rsyring","id":109467,"avatar_url":"https://avatars.githubusercontent.com/u/109467?v=3","gravatar_id":"","url":"https://api.github.com/users/rsyring","html_url":"https://github.com/rsyring","followers_url":"https://api.github.com/users/rsyring/followers","following_url":"https://api.github.com/users/rsyring/following{/other_user}","gists_url":"https://api.github.com/users/rsyring/gists{/gist_id}","starred_url":"https://api.github.com/users/rsyring/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsyring/subscriptions","organizations_url":"https://api.github.com/users/rsyring/orgs","repos_url":"https://api.github.com/users/rsyring/repos","events_url":"https://api.github.com/users/rsyring/events{/privacy}","received_events_url":"https://api.github.com/users/rsyring/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-23T17:27:20Z","updated_at":"2016-06-23T19:46:40Z","closed_at":null,"body":"##### ISSUE TYPE\r\n - Bug Report\r\n\r\n##### COMPONENT NAME\r\n\r\nservice module\r\n\r\n##### ANSIBLE VERSION\r\nI've seen the problem with both:\r\n\r\n```\r\nansible 2.1.0.0\r\n  config file = /etc/ansible/ansible.cfg\r\n  configured module search path = ['/usr/share/ansible']\r\nansible 1.9.6\r\n  configured module search path = /usr/share/ansible\r\n```\r\n\r\n##### CONFIGURATION\r\n\r\nOnly using default values.\r\n\r\n##### OS / ENVIRONMENT\r\n\r\nControl host: Ubuntu 14.04\r\nConnecting to: Ubuntu 14.04 on Docker version 1.9.1, build a34a1d5\r\n\r\n##### SUMMARY\r\n\r\nWhen using Ansible to connect to a docker container, restarting services using the service module does not work.  The task returns with a \"changed\" status but the process has not actually been restarted.\r\n\r\nVerified with both the sshd service and the nginx service.\r\n\r\n##### STEPS TO REPRODUCE\r\n\r\nBuild a docker image that can be used for this.  Example Dockerfile:\r\n\r\n```Dockerfile\r\n# Use phusion/baseimage as base image. To make your builds reproducible, make\r\n# sure you lock down to a specific version, not to `latest`!\r\n# See https://github.com/phusion/baseimage-docker/blob/master/Changelog.md for\r\n# a list of version numbers.\r\nFROM phusion/baseimage:0.9.18\r\n\r\n# Use baseimage-docker's init system.\r\nCMD [\"/sbin/my_init\"]\r\n\r\nRUN rm -f /etc/service/sshd/down\r\n\r\n# Regenerate SSH host keys. baseimage-docker does not contain any, so you\r\n# have to do that yourself. You may also comment out this instruction; the\r\n# init system will auto-generate one during boot.\r\nRUN /etc/my_init.d/00_regen_ssh_host_keys.sh\r\n\r\n# Keep this all by it's lonesome so we use the Docker cache and speed up development.\r\nRUN apt-get update -q \\\r\n    && apt-get install -y python2.7 \\\r\n\t&& ln -s /usr/bin/python2.7 /usr/bin/python\r\n\r\n# Clean up APT when done.\r\nRUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*\r\n```\r\n\r\nWork with the docker image to get a container running:\r\n\r\n```shell\r\n$ docker build -t ansible-service-bug .\r\n$ docker run ansible-service-bug /sbin/my_init --enable-insecure-key\r\n\r\n# open new terminal\r\n$ docker ps\r\nCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS             PORTS               NAMES\r\n310b7a26d6ed        nsible-service-bug   \"/sbin/my_init --enab\"   5 seconds ago       Up 5 seconds                            sad_goodall\r\n$ docker inspect -f \"{{ .NetworkSettings.IPAddress }}\" sad_goodall\r\n172.17.0.2\r\n```\r\n\r\nDownload the insecure key, test the ssh connection, verify the port sshd is running on:\r\n\r\n```shell\r\n$ curl -o insecure_key -fSL https://github.com/phusion/baseimage-docker/raw/master/image/services/sshd/keys/insecure_key\r\n$ ssh -i insecure_key root@172.17.0.2\r\nroot@310b7a26d6ed: cat /var/run/sshd.pid\r\n22  # this number could be different, but note it\r\n```\r\n\r\nRun the following playbook:\r\n\r\n```yaml\r\n- hosts: all\r\n  vars:\r\n    ansible_ssh_user: root\r\n  gather_facts: false\r\n  tasks:\r\n    - service: name=ssh state=restarted\r\n```\r\n\r\nWith the following command:\r\n```shell\r\n$ ansible-playbook -i 172.17.0.2, playbook.yaml --private-key insecure_key \r\n\r\nPLAY [all] ******************************************************************** \r\n\r\nTASK: [service name=ssh state=restarted] ************************************** \r\nchanged: [172.17.0.2]\r\n\r\nPLAY RECAP ******************************************************************** \r\n172.17.0.2                 : ok=1    changed=1    unreachable=0    failed=0  \r\n```\r\n\r\nNow, in the ssh connection that should still be open to the docker container:\r\n\r\n```shell\r\nroot@310b7a26d6ed: cat /var/run/sshd.pid\r\n22  # this number could be different, but note it\r\n```\r\n\r\n##### EXPECTED RESULTS\r\n\r\nI expected the pid of the sshd server to change.\r\n\r\n##### ACTUAL RESULTS\r\n\r\nThe restart task returns with a \"changed\" status but the service is not actually restarted.  The pid stays the same.\r\n\r\n##### ADDITIONAL INFO\r\n\r\n* I have verified the same behavior with nginx service.\r\n* I have verified that the service module works correctly when connecting to a non-docker server running on Linode.\r\n* I have verified that the service can be restarted using the init file directly and bypassing the service module.  See below for further details:\r\n\r\nChange the playbook to:\r\n\r\n```yaml\r\n- hosts: all\r\n  vars:\r\n    ansible_ssh_user: root\r\n  gather_facts: false\r\n  tasks:\r\n    - command: /etc/init.d/ssh restart\r\n```\r\n\r\nRun it again:\r\n\r\n```shell\r\n$ ansible-playbook -i 172.17.0.2, playbook.yaml --private-key insecure_key \r\n\r\nPLAY [all] ******************************************************************** \r\n\r\nTASK: [command /etc/init.d/ssh restart] *************************************** \r\nchanged: [172.17.0.2]\r\n\r\nPLAY RECAP ******************************************************************** \r\n172.17.0.2                 : ok=1    changed=1    unreachable=0    failed=0  \r\n```\r\nAnd in the ssh connection that should still be open to the docker container:\r\n\r\n```shell\r\nroot@310b7a26d6ed: cat /var/run/sshd.pid\r\n132  # this number could be different, but it should be different from the commands ran earlier.\r\n```"},"comment":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/comments/228162678","html_url":"https://github.com/ansible/ansible-modules-core/issues/4024#issuecomment-228162678","issue_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/4024","id":228162678,"user":{"login":"bcoca","id":836171,"avatar_url":"https://avatars.githubusercontent.com/u/836171?v=3","gravatar_id":"","url":"https://api.github.com/users/bcoca","html_url":"https://github.com/bcoca","followers_url":"https://api.github.com/users/bcoca/followers","following_url":"https://api.github.com/users/bcoca/following{/other_user}","gists_url":"https://api.github.com/users/bcoca/gists{/gist_id}","starred_url":"https://api.github.com/users/bcoca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcoca/subscriptions","organizations_url":"https://api.github.com/users/bcoca/orgs","repos_url":"https://api.github.com/users/bcoca/repos","events_url":"https://api.github.com/users/bcoca/events{/privacy}","received_events_url":"https://api.github.com/users/bcoca/received_events","type":"User","site_admin":false},"created_at":"2016-06-23T19:46:40Z","updated_at":"2016-06-23T19:46:40Z","body":"what is the value of the `ansible_service_mgr` fact for that container?"}}
{"actor":{"display_login":"bcoca"}}