Reputation: 1646
I have the following line in Ansible script:
- name: get UUID
shell: "blkid | grep test--tgroup* | grep xfs | awk -F : '{print "blkid -s UUID -o value "$1}' |sh"
register: UUID_value
I get the following error when I run the script:
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/etc/ansible/config/test.yml': line...
May be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
shell: "blkid | grep test--tgroup* | grep xfs | awk -F : '{print "blkid -s UUID -o value "$1}' |sh"
^ here
Can anyone tell me how to fix this syntax issue?
Upvotes: 0
Views: 525
Reputation: 59969
You need to escape the inner doublequotes.
- name: get UUID
shell: "blkid | grep test--tgroup* | grep xfs | awk -F : '{print \"blkid -s UUID -o value \"$1}' |sh"
register: UUID_value
If there wasn't the colon in your string you would have been able to just to remove the outer quotes, but that would raise another YAML error. Still, this is an option but you need to work around the colon problem like this:
- name: get UUID
shell: blkid | grep test--tgroup* | grep xfs | awk -F {{ ":" }} '{print "blkid -s UUID -o value "$1}' |sh
register: UUID_value
Explanation for this colon "escaping" can be found here or here or here.
Upvotes: 3
Reputation: 68439
You need to escape the double-quotes inside:
- name: get UUID
shell: "blkid | grep test--tgroup* | grep xfs | awk -F : '{print \"blkid -s UUID -o value \"$1}' |sh"
register: UUID_value
Upvotes: 1