Docker Compose Module Issue - Trying to Stop Some Services

221 views
Skip to first unread message

Kernel Panic

unread,
May 8, 2020, 11:32:22 PM5/8/20
to Ansible Project
Hello there, hope this is the right place to ask.

Im trying to accomplish  the following using docker_compose module, the idea is, I have a compose file which runs
some services and I want to stop some of them but not all, I know beforehands the ones that I do not want to stop, so
am trying to do the following, define vars with the services I do not want to stop, leave them running but the rest.
somehow this is not working for me, the when clause seems not to be being evaluated, services variable and 
running_services fact show their content, so is not empty, maybe the services tag in docker_compose expects something
different, if I run the following it just stops all the services.

Any hint really appreciated.

---
- hosts: all
  vars:
services:
  - service1
  - service2
      
  tasks:
- name: Get services
  # Retrieve list of services running and register the output.
  command: docker-compose -f /path/docker-compose.yml config --services
  register: list
 
# I define running_services fact with the content of list.
- set_fact:
running_services: " list.stdout_lines "

- name: Stop The Services
  docker_compose:
project_src: "/path"
services: " running_services"
state: present
stopped: yes
  when: running_services not in services


   - debug:
var: services

- debug:
var: running_services


services var output.
ok: [1.1.1.1] => {
    "services": [
        "service1",
        "service2"

    ]
}


running_services output
ok: [1.1.1.1] => {
    "running_services": [
        "service1",
        "service2",
        "service3",
        "app2",
        "app3"
        
    ]
}

Thanks
Regards


...

Stefan Hornburg (Racke)

unread,
May 9, 2020, 1:52:27 AM5/9/20
to ansible...@googlegroups.com
On 5/9/20 5:32 AM, Kernel Panic wrote:
> Hello there, hope this is the right place to ask.
>
> Im trying to accomplish  the following using docker_compose module, the idea is, I have a compose file which runs
> some services and I want to stop some of them but not all, I know beforehands the ones that I do not want to stop, so
> am trying to do the following, define vars with the services I do not want to stop, leave them running but the rest.
> somehow this is not working for me, the when clause seems not to be being evaluated, services variable and 
> running_services fact show their content, so is not empty, maybe the services tag in docker_compose expects something
> different, if I run the following it just stops all the services.
>
> Any hint really appreciated.

I think that defeats the purpose of docker-compose. You could stop the services with the docker_container module.

Regards
Racke
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/36ff7267-1fb4-4a23-ba26-2abf2423bdf1%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/36ff7267-1fb4-4a23-ba26-2abf2423bdf1%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc
Reply all
Reply to author
Forward
0 new messages