<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Namespace on ads' corner</title><link>https://andreas.scherbaum.la/tags/namespace/</link><description>Recent content in Namespace on ads' corner</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Thu, 09 Jul 2020 21:46:00 +0200</lastBuildDate><atom:link href="https://andreas.scherbaum.la/tags/namespace/index.xml" rel="self" type="application/rss+xml"/><item><title>Use namespace as global variable in Ansible Jinja templates</title><link>https://andreas.scherbaum.la/post/2020-07-09_use-namespace-as-global-variable-in-ansible-jinja-templates/</link><pubDate>Thu, 09 Jul 2020 21:46:00 +0200</pubDate><guid>https://andreas.scherbaum.la/post/2020-07-09_use-namespace-as-global-variable-in-ansible-jinja-templates/</guid><description>&lt;p&gt;A simple task, or so I thought: in a &lt;em&gt;Jinja&lt;/em&gt; template keep track of the number of items in a loop. And then use that count afterwards.&lt;/p&gt;&#10;&lt;p&gt;Disclaimer: the number of items is not equal the number of times the loop runs, so I can&amp;rsquo;t use the loop variables.&lt;/p&gt;&#10;&lt;p&gt;Turns out that &lt;em&gt;Jinja&lt;/em&gt; has other opinions, and variables inside a loop are all local. When a variable is changed inside the loop, the scope of the variable stays local, and once the loop ends the original value of the variable is restored. That&amp;rsquo;s even true for variables which are created outside the loop.&lt;/p&gt;</description></item></channel></rss>