I am using shell command to execute sed output piped to cut. Task in a playbook is as follow:
tasks:
- name: “Task 1: Fetch inv”
shell: ‘/bin/sed -n ‘/’{{ group }}’/,/^$/p’ {{ var_file }} | cut -d’=’ -s -f2’
register: scriptout - debug: var=scriptout
I have tested manually from the command prompt, it is working fine. But when running in an Ansible gives following error:
ERROR! Syntax Error while loading YAML.
The error appears to have been in ‘/home/ansible/playbooks/my.yml’: line 15, column 31, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
#shell: ‘{{ linux_script }} {{ var_file }} {{ group }}’
shell: ‘/bin/sed -n ‘/’{{ group }}’/,/^$/p’ {{ var_file }} | cut -d’=’ -s -f2’
^ 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 }}”
Please, someone can help me to understand the concept of escape characters should be used? Or pass the special characters as a string? and how to achieve the same?