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.
More on Security and Secrets
How do you set up a secure automation user and SSH access?BeginnerHow do you give the automation user sudo with least privilege?IntermediateWhat are the alternatives to Ansible Vault for secrets, and when do you use them?IntermediateHow do you read AWS Secrets Manager and SSM parameters in a playbook?IntermediateHow do you integrate HashiCorp Vault with Ansible?AdvancedHow do you stop secrets from leaking into logs and output?Beginner