Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload config with ansible docker_container module?

I am trying to accomplish docker kill -s HUP <container> in Ansible but it looks like the options I try always restart the container or attempt to instead of reloading the config.

Running the following command allows me to reload the configuration without restarting the container:

docker kill -s HUP <container>

The Ansible docker_container docs suggest the following options:

force_kill Use the kill command when stopping a running container.

kill_signal Override default signal used to kill a running container.

Using the kill_signal in isolation did nothing.

Below is an example of what I hoped would work:

- name: Reload haproxy config
  docker_container:
    name: '{{ haproxy_docker_name }}'
    state: stopped
    image: '{{ haproxy_docker_image }}'
    force_kill: True
    kill_signal: HUP

I assumed overriding force_kill and kill_signal would give me the desired behaviour. I have also tried setting state to 'started' and present.

What is the correct way to do this?

like image 823
kaizenCoder Avatar asked Nov 19 '22 05:11

kaizenCoder


1 Answers

I needed to do the same with an haproxy docker instance to reload the configuration. The following worked in ansible 2.11.2:

handlers:
  - name: Restart HAProxy
    docker_container:
      name: haproxy
      state: stopped
      force_kill: True
      kill_signal: HUP
like image 94
user14295178 Avatar answered Dec 05 '22 13:12

user14295178