[19:59] <Guest5035> had an issue today trying to understand: ami amazon/amzn2-ami-minimal-hvm-2.0.20220207.1-x86_64-ebs cloud init ran a user data script as expected, with a newer ami amzn2-ami-minimal-hvm-2.0.20220218.0-x86_64-ebs it did not work - I found a cat /var/lib/cloud/instance/user-data.txt.i which looked like:
[19:59] <Guest5035> Content-Type: multipart/mixed; boundary="[19:59] <Guest5035> MIME-Version: 1.0
[19:59] <Guest5035> Number-Attachments: 1
[19:59] <Guest5035> Number-Attachments: 1
[19:59] <Guest5035> --[19:59] <Guest5035> MIME-Version: 1.0
[19:59] <Guest5035> Content-Type: text/x-not-multipart
[19:59] <Guest5035> Content-Disposition: attachment; filename="part-001"
[19:59] <Guest5035> --[20:00] <Guest5035> any ideas?
[20:09] <guest007> ?
[22:52] <toolsmith> hello all. I just started using cloud-init through terraform for Azure. In poc mode right now and passing 64bitencoded shell file with template: jinja declaration. I can get basic jinja working but when trying to us the jinja 'do' statement I'm getting python stack trace. TemplateSyntaxError: Encountered unknown tag 'do'. Jinja was looking for the
[22:52] <toolsmith> following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.  The do statement is nested within a for statement like so.......{% set private_ips = [] %} {% for i in ds.meta_data.imds.network.interface[0].ipv4 %}   {% do private_ips.append(i.privateIpAddress) %} {% endfor %}
[22:54] <toolsmith> Is this possible in user-data processing?
[22:55] <blackboxsw> toolsmith: can you paste the "fullish" user-data to paste.ubuntu.com or https://paste.opendev.org/ ?
[22:57] <toolsmith> blackboxsw pasted, Paste #b9ydAg0GtZV8GRWvc5Vp
[23:01] <blackboxsw> toolsmith: thanks. trying to peek at it now and execise in a LXD. we should be able to iterate on this a bit locally using cloud-init cmdline of your azure instance with something  like the following `sudo cloud-init query --format '{% ... your template syntax %}' . I'm playing with something like your example now
[23:02] <toolsmith> ok, i'll see about running the cli tool on my instance as well
[23:02] <blackboxsw> for instance we can easily just construct a simple for loop and render the content of a list w/ `cloud-init query --format "{% set private_ips = [1, 2, 3] %} {% for i in private_ips %} {{ i }} {% endfor %}"`
[23:03] <toolsmith> yeah, it's the 'do' statement that is not being honored it seems.
[23:03] <blackboxsw> but yeah, I'm trying to understand your 'do' operations. I think we don't need/want the  "do" but I'm checking
[23:04] <toolsmith> My experience with jinja has been mostly with Saltstack and this is something I did in salt states all the time, so i figured i see if it's possible in cloud-init.
[23:05] <toolsmith> A pattern i use is 1. set empty array var 2. iterate some runtime data 3. append to the array 4. dump the array to a file or process some more.
[23:06] <toolsmith> At least that is how I had to do it within Saltstack states
[23:11] <blackboxsw> this seems to work for me to extend the list iteself, but it still emits the None return value for each iteration in the loop.  cloud-init query --format "{% set private_ips = [1, 2, 3] %} {% for i in private_ips %} {{ i }} {% endfor %}"
[23:11] <blackboxsw> wrong paste. sorry
[23:12] <blackboxsw> here: cloud-init query --format "{% set private_ips = [] %} {% for i in [1, 2, 3] %} {{ private_ips.append(i) }} {% endfor %} {{private_ips }}"
[23:13] <blackboxsw> for some reason if I just use {% private_ips.append(i) %} around the operation we'll get that "Encountered unknown tag 'private_ips'... expected "endfor" etc
[23:15] <toolsmith> yup, i get the same.
[23:15] <toolsmith> Thanks for the tip on cli query too ;-), that will save me time
[23:19] <blackboxsw> could mangle it a bit more with a jinja default() like so: cloud-init query --format "{% set private_ips = [] %} {% for i in [1, 2, 3] %} {{ private_ips.append(i) }} {% endfor %} {{private_ips }}"   
[23:20] <blackboxsw> anyhow I'm going to have to head out here, sorry just lobbing weak suggestions your way
[23:20] <blackboxsw> cloud-init query --format "{% set private_ips = [] %} {% for i in [1, 2, 3] %}{{ private_ips.append(i)|default('', True)}}{% endfor %} {{private_ips }}"
[23:21] <toolsmith> no problem. thanks for helping out.