JInja2 loops in YAML folded syntax

Hi,

I’m using a pip-installed Ansible 2.1.1.0 on a CentOS 7.

I’m trying to run the following task in a playbook:

  • name: guest_installed
    shell: >
    virt-install
    –name {{ guest.name }}
    –ram {{ guest.memsize }}
    –hvm
    –disk path=/dev/{{ vg }}/vm-{{ guest.name }}-image,bus=virtio,cache=none,format=raw
    {% for d in guest.transient_volumes + guest.persistent_volumes %}
    –disk path=/dev/{{ vg }}/vm-{{ guest.name }}-{{ d.name }},bus=virtio,cache=none,format=raw
    {% endfor %}

–location {{ install_image_destdir }}/centos7.iso
–vcpus 8
–os-type linux
–os-variant rhel7
–network bridge={{ guest.bridge }}
–graphics none
–initrd-inject={{ guest.name }}/ks.cfg
–extra-args=‘ks=file:/ks.cfg console=tty0 console=ttyS0,115200n8 serial’
–noreboot
–noautoconsole

As you can see, I’m building up some options for virt-install from a list of volumes. Anyhow, this syntax doesn’t quite work, I think because there is some clash between Jinja2 and the YAML parser. Whats happens is that the shell module tries to execute multiple commands, the first up to the first “–disk” option and the the other options as if they where single commands and not a continuation of the YAML folded string starting with >.

I could run the above module as follows:

  • name: guest_installed
    shell: >
    virt-install
    –name {{ guest.name }}
    –ram {{ guest.memsize }}
    –hvm
    –disk path=/dev/{{ vg }}/vm-{{ guest.name }}-image,bus=virtio,cache=none,format=raw
    –location {{ install_image_destdir }}/centos7.iso

–vcpus 8
–os-type linux
–os-variant rhel7
–network bridge={{ guest.bridge }}
–graphics none
–initrd-inject={{ guest.name }}/ks.cfg
–extra-args=‘ks=file:/ks.cfg console=tty0 console=ttyS0,115200n8 serial’
–noreboot
–noautoconsole {% for d in guest.transient_volumes + guest.persistent_volumes %}–disk path=/dev/{{ vg }}/vm-{{ guest.name }}-{{ d.name }},bus=virtio,cache=none,format=raw{% endfor %}

which is incredibly ugly. Is there anyway to accomplish this in a tidier way which doesn’t possibly involve templates and the script module?

Thanks and regards.

C.