ansible-role-docker icon indicating copy to clipboard operation
ansible-role-docker copied to clipboard

Support tag for log-opts

Open patsevanton opened this issue 3 years ago • 1 comments

Hello! Thanks ansible role docker. How configure tag for log-opts ?

Playbook

---
- hosts: javaindocker
  become: true
  pre_tasks:
    - name: Update apt cache.
      apt: update_cache=true cache_valid_time=600
      when: ansible_os_family == 'Debian'
    - name: install pip3
      apt: name=python3-pip state=present
    - name: Install multi python packages with version specifiers
      pip:
        name:
          - docker
          - docker-compose
  roles:
    - role: geerlingguy.docker

Inventory

all:
  children:
    javaindocker:
      hosts:
        "javaindocker":
          ansible_host: "xxxx"
  vars:
    docker_daemon_options:
      "log-driver": "json-file"
      "log-opts":
          "tag": "{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}"
          "max-size": "100m"

Error

TASK [geerlingguy.docker : Ensure /etc/docker/ directory exists.] **********************************************************************************************************************
Sunday 01 May 2022  13:53:05 +0600 (0:00:01.532)       0:00:16.139 ************
fatal: [javaindocker]: FAILED! =>
  msg: |-
    The conditional check 'docker_daemon_options.keys() | length > 0' failed. The error was: An unhandled exception occurred while templating '{'log-driver': 'json-file', 'log-opts': {'tag': '{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}', 'max-size': '100m'}}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: template error while templating string: unexpected '.'. String: {{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}

    The error appears to be in '/home/user/.ansible/roles/geerlingguy.docker/tasks/main.yml': line xx, column 3, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:


    - name: Ensure /etc/docker/ directory exists.
      ^ here

patsevanton avatar May 01 '22 08:05 patsevanton

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar Jul 31 '22 22:07 stale[bot]

Hey @patsevanton

I think Jinja may be trying to template {{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}

Try giving this a go:

all:
  # ...
  vars:
    docker_daemon_options:
      "log-driver": "json-file"
      "log-opts":
          "tag": "{% raw %}{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}{% endraw %}"
          "max-size": "100m"

Notice the {% raw %} and {% endraw %}: https://jinja.palletsprojects.com/en/3.1.x/templates/#escaping

dbrennand avatar Oct 01 '22 16:10 dbrennand

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar Jan 07 '23 15:01 stale[bot]

I can confirm that @dbrennand way is working. Maybe you could document that.

sebastiangaiser avatar Jan 17 '23 15:01 sebastiangaiser

This issue is no longer marked for closure.

stale[bot] avatar Jan 17 '23 15:01 stale[bot]

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar May 21 '23 23:05 stale[bot]

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.

github-actions[bot] avatar Jul 24 '23 06:07 github-actions[bot]