ansible-role-docker
ansible-role-docker copied to clipboard
Support tag for log-opts
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
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.
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
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.
I can confirm that @dbrennand way is working. Maybe you could document that.
This issue is no longer marked for closure.
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.
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.