/srv/irclogs.ubuntu.com/2022/03/01/#cloud-init.txt

Guest5035had 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
Guest5035Content-Type: multipart/mixed; boundary="===============2079083206506282502=="19:59
Guest5035MIME-Version: 1.019:59
Guest5035Number-Attachments: 119:59
Guest5035Number-Attachments: 119:59
Guest5035--===============2079083206506282502==19:59
Guest5035MIME-Version: 1.019:59
Guest5035Content-Type: text/x-not-multipart19:59
Guest5035Content-Disposition: attachment; filename="part-001"19:59
Guest5035--===============2079083206506282502==--19:59
Guest5035any ideas?20:00
guest007?20:09
=== paride1 is now known as paride
=== meena9 is now known as meena
=== falcojr9 is now known as falcojr
=== bahamat_ is now known as bahamat
toolsmithhello 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 the22:52
toolsmithfollowing 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:52
toolsmithIs this possible in user-data processing?22:54
blackboxswtoolsmith: can you paste the "fullish" user-data to paste.ubuntu.com or https://paste.opendev.org/ ?22:55
toolsmithblackboxsw pasted, Paste #b9ydAg0GtZV8GRWvc5Vp22:57
blackboxswtoolsmith: 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 now23:01
toolsmithok, i'll see about running the cli tool on my instance as well23:02
blackboxswfor 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:02
toolsmithyeah, it's the 'do' statement that is not being honored it seems.23:03
blackboxswbut yeah, I'm trying to understand your 'do' operations. I think we don't need/want the  "do" but I'm checking23:03
toolsmithMy 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:04
toolsmithA 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:05
toolsmithAt least that is how I had to do it within Saltstack states23:06
blackboxswthis 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
blackboxswwrong paste. sorry23:11
blackboxswhere: cloud-init query --format "{% set private_ips = [] %} {% for i in [1, 2, 3] %} {{ private_ips.append(i) }} {% endfor %} {{private_ips }}"23:12
blackboxswfor some reason if I just use {% private_ips.append(i) %} around the operation we'll get that "Encountered unknown tag 'private_ips'... expected "endfor" etc23:13
toolsmithyup, i get the same.23:15
toolsmithThanks for the tip on cli query too ;-), that will save me time23:15
blackboxswcould 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:19
blackboxswanyhow I'm going to have to head out here, sorry just lobbing weak suggestions your way23:20
blackboxswcloud-init query --format "{% set private_ips = [] %} {% for i in [1, 2, 3] %}{{ private_ips.append(i)|default('', True)}}{% endfor %} {{private_ips }}"23:20
toolsmithno problem. thanks for helping out.23:21

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!