Open waynr opened 4 years ago
Hi,
Let me answer that one with a question of my own. What benefits would there be for introducing a 2nd dict based variable to define the same configuration that's configurable using the existing variable?
Given that Ansible is built around the use of a templated yaml DSL to define configuration values, it is simply more idiomatic to write
docker__default_daemon_json_dict:
log-driver: journald
than
docker__default_daemon_json: |
"log-driver": "journald"
Additionally, notice the impact on syntax highlighting in the above two examples of cramming a dictionary data structure into a string as is done with docker__default_daemon_json
.
Finally, consider a slightly more complicated example:
docker__default_daemon_json_dict:
log-opts:
max-size: "10m"
max-file: "5"
labels: "somelabel"
env: "os,customer"
the to_pretty_json
filter makes a syntactically correct, pretty json file with all the necessary indentation
docker__default_daemon_json: |
"log-opts": { "max-size": "10m", "max-file":"5", "labels": "somelabel", "env": "os,customer" }
this is comparatively more difficult to write, produces less pretty output, and may not even produce correct json on the first try
Ah, I was coming at it from someone who might have ported over a manual installation of Docker to Ansible and now they wanted to copy / paste their existing json file into a multi-line string.
But yes, using a dict would be more readable from a configuration POV. Let's talk more about the implementation in your PR.
Hey, first off thanks for providing a nice-looking docker ansible role!
When I set out to find a preexisting docker role I was hoping to find something that allows daemon.json to data to be specified as a dict rather than as a string of jsonish key-values, ie:
So I've got two questions for you:
to_json
filter? and if so, did you have a particular reason for going with the approach you ultimately ended up with?docker__daemon_json_dict
that, if set, would be preferred over the existing default behavior.Thanks for your consideration!