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

docker_stack does not update config #841

Open
autokilla47 opened this issue Apr 24, 2024 · 0 comments
Open

docker_stack does not update config #841

autokilla47 opened this issue Apr 24, 2024 · 0 comments

Comments

@autokilla47
Copy link

I described the following ansible tasks. When changing haproxy.cfg file, you need to apply it, but at docker_stack task the haproxy.cfg remains the previous one, although the new one is already present in the docker-compose.yaml. If you make changes to the haproxy.cfg again, then the previous one is applied, and each time it is not the new but the previous config that is applied. And only if you add the last task (ansible.builtin.shell), then in this case the newest haproxy.cfg is applied.
Should a docker_stack update configs when called?

- set_fact:
    haproxy_cfg_date: "{{ ansible_date_time.time | replace(':', '_') }}"

- ansible.builtin.template:
    src: haproxy.cfg.j2
    dest: "{{ haproxy_docker_dir }}/haproxy.cfg"
  register: haproxy_conf
  
- ansible.builtin.template:
    src: docker-compose.yaml.j2
    dest: "{{ haproxy_docker_dir }}/docker-compose.yaml"
  when: haproxy_conf.changed
  
- community.docker.docker_stack:
    state: present
    name: haproxy
    compose:
      - "{{ haproxy_docker_dir }}/docker-compose.yaml"
  run_once: true
  
- ansible.builtin.shell: docker stack deploy -c docker-compose.yaml haproxy
  args:
    chdir: "{{ haproxy_docker_dir }}"
  run_once: true
  when: haproxy_conf.changed

Docker-compose.yaml file:

    configs:
      - source: haproxy.cfg
        target: /usr/local/etc/haproxy/haproxy.cfg

configs:
  haproxy.cfg:
    name: haproxy.cfg-{{ haproxy_cfg_date }}
    file: ./haproxy.cfg

ansible [core 2.15.10]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True

docker module version
7.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants