# \[community.docker.docker\_stack\] How to use variables in inline compose definition?

**URL:** <https://forum.ansible.com/t/community-docker-docker-stack-how-to-use-variables-in-inline-compose-definition/10998>\
**Category:** Get Help\
**Tags:** docker-swarm, docker-compose, galaxy-ng\
**Created:** [November 19, 2024, 12:09pm UTC](https://forum.ansible.com/t/community-docker-docker-stack-how-to-use-variables-in-inline-compose-definition/10998 "2024-11-19T12:09:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FSeidinger](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/fseidinger/32/5338_2.png) [@FSeidinger](https://forum.ansible.com/u/FSeidinger)\
**Post date:** [November 19, 2024, 12:09pm UTC](https://forum.ansible.com/t/community-docker-docker-stack-how-to-use-variables-in-inline-compose-definition/10998/1 "2024-11-19T12:09:27Z")

</div>

I want to use the docker\_config and the docker\_stack module to update a swarm configuration used by a service.

The playbook first creates a new version of the swarm configuration with the docker\_config module and then tries to update the running stack to pick up the new configuration.

The example of the [docker\_stack](https://galaxy.ansible.com/ui/repo/published/community/docker/content/module/docker_stack) module with an inlined compose file is taken from the examples section of the official module documentation.

This is my playbook:

```auto
- name: Update swarm cluster
  hosts: camina.m.internal
  tasks:
    - name: Update Traefik configuration
      community.docker.docker_config:
        name: traefik.yaml
        debug: true
        versions_to_keep: 2
        rolling_versions: true
        data: "{{ lookup('file', 'etc/traefik/traefik.yaml') }}"
        state: present
      register: traefik_config

    - name: Update traefik service
      community.docker.docker_stack:
        name: traefik
        state: present
        compose:
          - /srv/cloud/traefik/compose.yml
          - version: '3'
            configs:
              "{{ traefik_config.config_name }}":
                name: traefik.yaml
                external: true

```

Unfortunately the docker\_stack module seems not to resolve variables in the inline compose definition.

I get the error:

```auto
fatal: [camina.m.internal]: FAILED! => {"changed": false, "msg": "docker stack up deploy command failed", "rc": 1, "stderr": "configs Additional property {{ traefik_config.config_name }} is not allowed\n", "stderr_lines": ["configs Additional property {{ traefik_config.config_name }} is not allowed"], "stdout": "", "stdout_lines": []}

```

---

<div class="post-metadata">

**Author:** ![FSeidinger](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/fseidinger/32/5338_2.png) [@FSeidinger](https://forum.ansible.com/u/FSeidinger)\
**Post date:** [November 19, 2024, 12:25pm UTC](https://forum.ansible.com/t/community-docker-docker-stack-how-to-use-variables-in-inline-compose-definition/10998/2 "2024-11-19T12:25:31Z")

</div>

Sorry got that wrong. I mistakenly muddled up the name of the config with the config itself.

This example is working as expected:

```auto
- name: Update swarm cluster
  hosts: camina.m.internal
  tasks:
    - name: Update Traefik configuration
      community.docker.docker_config:
        name: traefik.yaml
        debug: true
        versions_to_keep: 2
        rolling_versions: true
        data: "{{ lookup('file', 'etc/traefik/traefik.yaml') }}"
        state: present
      register: traefik_config

    - name: Update traefik service
      community.docker.docker_stack:
        name: traefik
        state: present
        compose:
          - /srv/cloud/traefik/compose.yml
          - version: '3'
            configs:
              traefik.yaml:
                name: "{{ traefik_config.config_name }}"
                external: true

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 19, 2024, 12:26pm UTC](https://forum.ansible.com/t/community-docker-docker-stack-how-to-use-variables-in-inline-compose-definition/10998/3 "2024-12-19T12:26:00Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
