i am new to Ansible, and have write .yml file to empty a file, just like ">file_name"
---
tasks:
- name: Empty Log Files greater then 400M
shell: 'find "{{ item }}" -name "messages*" -size +400M -exec sh -c '> {}' \;'
with_items:
- /var/log
- /var/opt
- /var/spool/mail
ignore_errors: yes
and i am getting this following error
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/tmp/clean.yml': line 7, column 11, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
name: Delete Log Files greater then 400M shell: 'find "{{ item }}" -name "messages*" -size +400M -exec sh -c '> {}' \;' ^ here We could be wrong, but this one looks like it might be an issue with missing quotes. Always quote template expression brackets when they start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items: - "{{ foo }}"
exception type: exception: mapping values are not allowed in this context in "", line 7, column 11
where im getting it wrong?
find:
module instead of shell command. docs.ansible.com/ansible/latest/modules/find_module.html...the yml syntax plays an important role in ansible....you should validate your syntax using ansible` --syntax-check` option – error404