How can I use jinja2 to join with quotes in Ansible?

Why not simply join it with the quotes?

"{{ hosts | join('", "') }}"

Ansible has a to_json, to_nice_json, or a to_yaml in it's filters:

{{ some_variable | to_json }}
{{ some_variable | to_yaml }}

Useful if you are outputting a JSON/YAML or even (it's a bit cheeky, but JSON mostly works) a python config file (ie Django settings).

For reference: https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters-for-formatting-data

Tags:

Ansible