I'm writing an ansible playbook, which I'm fairly to. I'm having issues with ansible-playbook
complaining about my quotes, which from my understanding are correct. I've tried 3 things described at the bottom, one of them is what documentation says I should be doing and the other two are just to try workarounds that work in other playbooks when encountering this error telling me to add quotes when the quotes are already there. Ansible is inconsistent in how it wants variables quoted, any advice on exactly how to quote this or an explanation of Ansible's weirdness regarding quotes would be appreciated.
From my playbook:
- name: set template_src and template_dest variables
set_fact:
template_src: {{ path_to_vm_directory }}/"{{ name_of_vm_to_reset }}"/"{{ name_of_vm_to_reset >
template_dest: {{ path_to_vm_directory }}/"{{ name_of_vm_to_reset }}"/"{{ name_of_vm_to_reset>
- name: copy TEMPLATEv1 vdisk to become this VM's current vdisk "{{ name_of_vm_to_reset }}"
ansible.builtin.copy:
src: "{{ template_src }}"
dest: "{{ template_dest }}"
remote_src: true #src is on remote filesystem
mode: 644
owner: root
group: root
Which generates the following error message from ansible-playbook
(sorry about the code blocks, SE has some wonky parsing of large code blocks):
ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: Expecting value: line 1 column 1 (char 0) Syntax Error while loading YAML did not find expected key. while parsing a block mapping in "<unicode string>", line 81, column 11 did not find expected key in "<unicode string>", line 81, column 51
The error appears to be in '/home/microbot/ansible/test/playbook-metaverse-restore_to_template_BM0_any-vm.yaml': line 81, column 51, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
set_fact:
template_src: {{ path_to_vm_directory }}/"{{ name_of_vm_to_reset }}"/"{{ name_of_vm_to_reset }}".qcow2"{{ vdisk_template_filename_suffix }}"
^ here
Variations I've tried:
Quote each variable individually - as far as I am aware, this is correct according to Ansible documentation:
template_src: "{{ path_to_vm_directory }}"/"{{ name_of_vm_to_reset }}"/"{{ name_of_vm_to_reset }}".qcow2"{{ vdisk_template_filename_suffix }}"
Quote all but the first variable:
I've seen before that Ansible doesn't seem to like it when I start a string with a quoted variable - it will throw an error when quoted and no error when unquoted. But that's not happening this time for some reason.template_src: {{ path_to_vm_directory }}/"{{ name_of_vm_to_reset }}"/"{{ name_of_vm_to_reset }}".qcow2"{{ vdisk_template_filename_suffix }}"
Quote nothing:
template_src: {{ path_to_vm_directory }}/{{ name_of_vm_to_reset }}/{{ name_of_vm_to_reset }}.qcow2{{ vdisk_template_filename_suffix }}