Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support config rotate for docker_config #109

Open
ieugen opened this issue Mar 25, 2021 · 4 comments
Open

Support config rotate for docker_config #109

ieugen opened this issue Mar 25, 2021 · 4 comments
Labels
docker-swarm Docker Swarm enhancement New feature or request

Comments

@ieugen
Copy link

ieugen commented Mar 25, 2021

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
  • Feature Idea
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.

- name: Configuration for kibana
  community.docker.docker_config:
    name: kibana_config
    state: present
    data: "{{ lookup('file', 'files/monitoring_elk/kibana.yml') }}"

- name: monitoring_elk
  community.docker.docker_stack:
    state: present
    name: monitoring_elk
    prune: yes
    compose:
      - version: "3.8"
        services:
          elasticsearch:
          kibana:
            image: "docker.elastic.co/kibana/kibana:7.12.0"
            #REDACTED
            configs:
              - source: kibana_config
                target: /usr/share/kibana/config/kibana.yml
@ieugen
Copy link
Author

ieugen commented Mar 25, 2021

One option would be to enahance docker_config with an option that allows it to:

  • create a new config using the name as prefix + file checksum ( first 6-10 characters of checksum should be enough IMO)
    The new option for docker_config would be 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.

@felixfontein felixfontein added the docker-swarm Docker Swarm label Mar 25, 2021
@felixfontein
Copy link
Collaborator

A somewhat related issue is #21.

@ieugen
Copy link
Author

ieugen commented Mar 26, 2021

I have found a workaround that seems to work ok for now:

  • Use set_fact in ansible to get the contents and compute the file hash
  • Use the hash to version the docker_config
  • Use that in the service

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

@imartinezortiz
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker-swarm Docker Swarm enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants