Interview Prep/Ansible/Security and Secrets

What does the `quote` filter do and when is it needed?

IntermediateProductionSecurity and Secrets
Answer

quote shell-escapes a value so it is treated as one literal word by /bin/sh. It is needed any time a variable is placed in a shell: (or raw:) command line, especially with spaces, ;, $, or backticks.

- ansible.builtin.shell: "tar czf {{ backup_file | quote }} {{ data_dir | quote }}"

For command: with the argv form, quoting is not required because there is no shell. Prefer argv when possible.

All Ansible questions Roadmap: Ansible

More on Security and Secrets