{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/502","labels_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/502/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/502/comments","events_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/502/events","html_url":"https://github.com/ansible/ansible-modules-core/pull/502","id":51848524,"number":502,"title":"[wip] Docker: state reorganization and pull option","user":{"login":"smashwilson","id":17565,"avatar_url":"https://avatars.githubusercontent.com/u/17565?v=3","gravatar_id":"","url":"https://api.github.com/users/smashwilson","html_url":"https://github.com/smashwilson","followers_url":"https://api.github.com/users/smashwilson/followers","following_url":"https://api.github.com/users/smashwilson/following{/other_user}","gists_url":"https://api.github.com/users/smashwilson/gists{/gist_id}","starred_url":"https://api.github.com/users/smashwilson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smashwilson/subscriptions","organizations_url":"https://api.github.com/users/smashwilson/orgs","repos_url":"https://api.github.com/users/smashwilson/repos","events_url":"https://api.github.com/users/smashwilson/events{/privacy}","received_events_url":"https://api.github.com/users/smashwilson/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/cloud","name":"cloud","color":"c7def8"},{"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/feature_pull_request","name":"feature_pull_request","color":"009800"},{"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/needs_info","name":"needs_info","color":"eb6420"},{"url":"https://api.github.com/repos/ansible/ansible-modules-core/labels/P2","name":"P2","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":29,"created_at":"2014-12-12T20:19:33Z","updated_at":"2015-03-05T20:06:50Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/pulls/502","html_url":"https://github.com/ansible/ansible-modules-core/pull/502","diff_url":"https://github.com/ansible/ansible-modules-core/pull/502.diff","patch_url":"https://github.com/ansible/ansible-modules-core/pull/502.patch"},"body":"This adds a `pull` option to the Docker module, which has two possible settings:\r\n\r\n * `missing` *(default)*. The named image and tag will only be pulled if missing from the host. This is backwards-compatible with the existing behavior.\r\n * `always`. A pull will always be performed to check for more recent builds first. If an existing container is already running with an older version of that image, it will be stopped and restarted.\r\n\r\nThe use case that this captures is continuous delivery of a Docker image. You can use a task like this one:\r\n\r\n```yaml\r\n  - name: Run the docker container\r\n    docker: pull=always image=smashwilson/minimal-sinatra name=minimal-sinatra ports=80:4567 state=running\r\n```\r\n\r\n... where \"smashwilson/minimal-sinatra\" is a container that's generated by an automated build on DockerHub, for example. Each time you execute the play, Ansible will ensure that the most recent build of that image is running. Without this, I find myself using ugly workarounds like:\r\n\r\n```yaml\r\n- name: pull the latest docker build\r\n  command: docker pull myimage\r\n  register: myimage\r\n  changed_when: outsideimage.stdout.find('Downloaded newer image') != -1\r\n  sudo: yes\r\n\r\n- name: stop the older image\r\n  docker: image=myimage name=mycontainer state=absent\r\n  when: myimage | changed\r\n  sudo: yes\r\n\r\n- name: launch the service\r\n  docker: image=myimage name=mycontainer state=running\r\n  sudo: yes\r\n```\r\n\r\nBut you don't *always* want to attempt to pull the latest on every deployment. It would be inconvenient if your database container was unconditionally restarted, for example, and upgraded under your feet. For that reason and for backwards compatibility I gated this behind an module option.\r\n\r\nThis has been requested before, specifically in #27."},"comment":{"url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/comments/77441036","html_url":"https://github.com/ansible/ansible-modules-core/pull/502#issuecomment-77441036","issue_url":"https://api.github.com/repos/ansible/ansible-modules-core/issues/502","id":77441036,"user":{"login":"smashwilson","id":17565,"avatar_url":"https://avatars.githubusercontent.com/u/17565?v=3","gravatar_id":"","url":"https://api.github.com/users/smashwilson","html_url":"https://github.com/smashwilson","followers_url":"https://api.github.com/users/smashwilson/followers","following_url":"https://api.github.com/users/smashwilson/following{/other_user}","gists_url":"https://api.github.com/users/smashwilson/gists{/gist_id}","starred_url":"https://api.github.com/users/smashwilson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smashwilson/subscriptions","organizations_url":"https://api.github.com/users/smashwilson/orgs","repos_url":"https://api.github.com/users/smashwilson/repos","events_url":"https://api.github.com/users/smashwilson/events{/privacy}","received_events_url":"https://api.github.com/users/smashwilson/received_events","type":"User","site_admin":false},"created_at":"2015-03-05T20:06:50Z","updated_at":"2015-03-05T20:06:50Z","body":"Hmm, I didn't touch that, and it still looks like it's there...\r\n\r\nMake sure your `~/Work/ansible-modules-core/` repo is on the right branch - it should be `docker-pull-option`."}}