Open ieugen opened 3 years ago
One option would be to enahance docker_config with an option that allows it to:
generate_name
?!
In the example case above this would be kibana_config_a3d12341
,
This new name can be registered as an ansible variable to be used in the stack deployment.docker_config could also have a prune
option to remove older configs.
The prune
option could be an integer to limit the number of configs kept in history?
If prune is 5 it should keep max 5 versions.
If prune is 0 it should keep only current version.
This would make stack deployments idempotent IMO.
A somewhat related issue is #21.
I have found a workaround that seems to work ok for now:
Does not work with docker_swarm_stack since it can't accept jinja interpolation in config name.
- name: Configuration contents for kibana config
set_fact:
kibana_config_contents: "{{ lookup('file', 'files/monitoring_elk/kibana.yml') }}"
- name: Configuration version for kibana
set_fact:
kibana_config_version: "{{ kibana_config_contents | checksum | truncate(6,True,'') }}"
- community.docker.docker_config:
name: "kibana_config_{{ kibana_config_version }}"
state: present
data: "{{ kibana_config_contents }}"
- name: ELK kibana
community.docker.docker_swarm_service:
# REDACTED
configs:
- config_name: "kibana_config_{{ kibana_config_version }}"
filename: /usr/share/kibana/config/kibana.yml
@ieugen just checked that after #295 it is possible to rotate a config in a docker swarm stack. This playbook it is a basic playbook (nginx + php-fpm) that I've used to test the approach. Just change the PHP DEBUG constant in the app_config
and run the playbook.
SUMMARY
I would like to be able to change a configuration of a docker service/stack that I deploy via ansible.
The functionality is described here https://docs.docker.com/engine/swarm/configs/#example-rotate-a-config .
Right now the docker_config fails to update since a service is using it. Docker supports create + rm, not update. Hence,
ISSUE TYPE
COMPONENT NAME
docker_config
ADDITIONAL INFORMATION
Using a playbook like bellow, if I update the config content and run the playbook, it will fail because it tries to update the config (by removing and adding it again). Removing fails because the configuration is used by the service.