<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>series: Ansible 2.20 gotchas Archives - Hécate Regnier - Neurozone</title>
	<atom:link href="https://hecate.neurozone.fr/tag/series-ansible-2-20-gotchas/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>DBA, DevOps &#38; Sysadmin</description>
	<lastBuildDate>Mon, 02 Nov 2026 17:04:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.5</generator>

<image>
	<url>https://hecate.neurozone.fr/wp-content/uploads/2026/10/cropped-avatar_Instagram-150x150.webp</url>
	<title>series: Ansible 2.20 gotchas Archives - Hécate Regnier - Neurozone</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">258172890</site>	<item>
		<title>Ansible 2.20 gotchas: string booleans from -e, tags that drop fact gathering, and lost handlers</title>
		<link>https://hecate.neurozone.fr/2026/12/02/ansible-2-20-gotchas-string-booleans-fact-gathering-lost-handlers/</link>
					<comments>https://hecate.neurozone.fr/2026/12/02/ansible-2-20-gotchas-string-booleans-fact-gathering-lost-handlers/#respond</comments>
		
		<dc:creator><![CDATA[Hécate Regnier]]></dc:creator>
		<pubDate>Wed, 02 Dec 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[Sysadmin notebook]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Ansible]]></category>
		<category><![CDATA[ansible-core]]></category>
		<category><![CDATA[series: Ansible 2.20 gotchas]]></category>
		<category><![CDATA[sysadmin notebook]]></category>
		<guid isPermaLink="false">https://hecate.neurozone.fr/?p=2794</guid>

					<description><![CDATA[<p>Three traps from migrating to ansible-core 2.20: -e var=false is a string, play-level tags remove fact gathering, and handlers lost after an interrupted run.</p>
<p>The post <a href="https://hecate.neurozone.fr/2026/12/02/ansible-2-20-gotchas-string-booleans-fact-gathering-lost-handlers/">Ansible 2.20 gotchas: string booleans from -e, tags that drop fact gathering, and lost handlers</a> appeared first on <a href="https://hecate.neurozone.fr">Hécate Regnier - Neurozone</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Since ansible-core 2.19, Ansible is much stricter about types, and Ansible 2.20 made the consequences visible in my playbooks. Migrating, I hit three traps in a row: a boolean that was really a string, fact gathering that silently disappeared when a play carried tags, and handlers that never ran after an interrupted run. Each one hides a real bug rather than creating one, which is why they are worth knowing.</p>



<figure class="wp-block-image size-full"><a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/ansible-2-20-gotchas-string-booleans-fact-gathering-lost-handlers_diagram_en.webp"><img fetchpriority="high" decoding="async" width="1720" height="960" src="https://hecate.neurozone.fr/wp-content/uploads/2026/11/ansible-2-20-gotchas-string-booleans-fact-gathering-lost-handlers_diagram_en.webp" alt="Diagram of three Ansible 2.20 traps: string booleans from -e, tags dropping fact gathering, lost handlers" class="wp-image-3172" srcset="https://hecate.neurozone.fr/wp-content/uploads/2026/11/ansible-2-20-gotchas-string-booleans-fact-gathering-lost-handlers_diagram_en.webp 1720w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/ansible-2-20-gotchas-string-booleans-fact-gathering-lost-handlers_diagram_en-300x167.webp 300w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/ansible-2-20-gotchas-string-booleans-fact-gathering-lost-handlers_diagram_en-1024x572.webp 1024w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/ansible-2-20-gotchas-string-booleans-fact-gathering-lost-handlers_diagram_en-768x429.webp 768w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/ansible-2-20-gotchas-string-booleans-fact-gathering-lost-handlers_diagram_en-1536x857.webp 1536w" sizes="(max-width: 800px) 100vw, 760px" /></a><figcaption class="wp-element-caption">Each trap, why it happens and the fix.</figcaption></figure>



<h2 class="wp-block-heading">At a glance</h2>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>Trap</th><th>What you see</th><th>Fix</th></tr></thead><tbody><tr><td><code>-e var=false</code> is a string</td><td><code>Conditional result (True) was derived from value of type 'str'</code></td><td>Pass JSON or a file, or use <code>| bool</code> in the role</td></tr><tr><td>Play-level <code>tags:</code> removes the <code>always</code> tag from fact gathering</td><td>Tasks reading <code>ansible_facts</code> fail or get it wrong on <code>--tags</code> runs</td><td><code>gather_facts: false</code> plus an explicit <code>setup</code> task tagged <code>always</code></td></tr><tr><td>Lost handlers</td><td><code>changed=0</code> on the re-run, but the service still runs the old config</td><td>Restart by hand, <code>force_handlers</code>, <code>flush_handlers</code>, and validate before installing</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">-e var=false is not a boolean</h2>



<p class="wp-block-paragraph">The most visible consequence of the stricter types is in conditionals: a <code>when:</code> clause must now produce a <strong>real boolean</strong>. Before, a non-empty string was silently treated as true. Now it&#8217;s an error.</p>



<h3 class="wp-block-heading">The command-line trap</h3>



<p class="wp-block-paragraph">The most common case: turning an option off for one deployment.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">ansible-playbook play.yml -e crowdsec_prometheus_enabled=false</pre>



<p class="wp-block-paragraph">With the <code>key=value</code> syntax, <code>-e</code> always produces <strong>strings</strong>. So the variable is <code>"false"</code>, a five-character string, not the boolean <code>false</code>. In a role doing <code>when: crowdsec_prometheus_enabled</code>, ansible-core 2.20 stops:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">Task failed: Conditional result (True) was derived from value of type 'str'
at "&lt;CLI option '-e'&gt;". Conditionals must have a boolean result.</pre>



<p class="wp-block-paragraph">The message is precise, too: it names the offending type (<code>str</code>) and where the value came from (the <code>-e</code> option). With an older version, the string <code>"false"</code> would have evaluated as <em>true</em>, since it isn&#8217;t empty: the task would have run when you meant to turn it off. So the new strictness prevents a real bug.</p>



<h3 class="wp-block-heading">Three right ways to do it</h3>



<ul class="wp-block-list"><li><strong>Pass JSON</strong>, which keeps types: <code>-e '{"crowdsec_prometheus_enabled": false}'</code>;</li><li><strong>pass a file</strong>, YAML or JSON: <code>-e @overrides.yml</code>, where <code>false</code> is a real boolean;</li><li><strong>in the role</strong>, explicitly convert variables that may come from the command line: <code>when: crowdsec_prometheus_enabled | bool</code>. The <code>bool</code> filter understands <code>"false"</code>, <code>"no"</code>, <code>"0"</code>…</li></ul>



<h2 class="wp-block-heading">Another Ansible 2.20 change: tags and fact gathering</h2>



<p class="wp-block-paragraph">Another surprise during the same migration: if a play itself carries <code>tags:</code>, the implicit &#8220;Gathering Facts&#8221; task loses its <code>always</code> tag. A <code>--tags</code> run that doesn&#8217;t target the play&#8217;s tag then skips fact gathering, and every task reading <code>ansible_facts</code> fails or gets it wrong. The fix is to turn off implicit gathering and replace it with an explicit task tagged <code>always</code>:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml">- hosts: all
  gather_facts: false
  tags: [base]
  pre_tasks:
    - name: Gather facts
      ansible.builtin.setup:
      tags: [always]</pre>



<p class="wp-block-paragraph">Moral: after a major ansible-core upgrade, run every playbook in <code>--check</code>, including with targeted <code>--tags</code>, before trusting any deployment.</p>



<h2 class="wp-block-heading">Lost handlers</h2>



<p class="wp-block-paragraph">Handlers are one of Ansible&#8217;s handiest mechanisms: a task that changes a config file &#8220;notifies&#8221; a handler (<code>restart nginx</code>), and that handler runs only once, at the end of the play, and only if something changed. But that behaviour hides a trap.</p>



<h3 class="wp-block-heading">The scenario</h3>



<ul class="wp-block-list"><li>a playbook changes CrowdSec&#8217;s config: the task goes <code>changed</code> and notifies <code>restart crowdsec</code>;</li><li>further on, another task fails (a package not found, a command erroring out);</li><li>the play stops. By default, <strong>pending handlers don&#8217;t run</strong>;</li><li>I fix it and re-run. The config is already up to date on disk: the task is <code>ok</code>, notifies nothing, and the handler is never called;</li><li>result: <code>changed=0</code>, everything looks fine… but CrowdSec is still running the <em>old</em> config loaded in memory.</li></ul>



<p class="wp-block-paragraph">The trap is that disk state and in-memory state diverge without any signal showing it. I found out because a functional check failed, even though the file was clearly correct.</p>



<h3 class="wp-block-heading">The fixes</h3>



<ul class="wp-block-list"><li><strong>By hand, after a failure</strong>: restart or reload the affected services. Make it a reflex whenever a run is interrupted;</li><li><strong><code>force_handlers: true</code></strong> at play level: notified handlers run even if a later task fails;</li><li><strong><code>meta: flush_handlers</code></strong> right after the config tasks, to apply restarts before the risky steps.</li></ul>



<h3 class="wp-block-heading">The downside of force_handlers</h3>



<p class="wp-block-paragraph"><code>force_handlers</code> isn&#8217;t a silver bullet. In my mail server role, the config was deployed, notified a restart, then got <em>validated</em> by a later task. The day validation failed, <code>force_handlers</code> restarted the service anyway with the invalid config, and it crash-looped for a minute.</p>



<p class="wp-block-paragraph">The right structure is to validate <strong>before</strong> installing:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="yaml">- name: Render config to a staging directory
  ansible.builtin.template:
    src: mox.conf.j2
    dest: /home/mox/config/.staging/mox.conf

- name: Validate the staged config
  ansible.builtin.command: /home/mox/mox config test -config /home/mox/config/.staging/mox.conf
  changed_when: false

- name: Install the validated config
  ansible.builtin.copy:
    src: /home/mox/config/.staging/mox.conf
    dest: /home/mox/config/mox.conf
    remote_src: true
  notify: restart mox</pre>



<p class="wp-block-paragraph">That way an invalid config never reaches the real file, and no handler gets notified. You can then keep <code>force_handlers</code> safely. It&#8217;s also the idea behind the <code>template</code> module&#8217;s <code>validate:</code> option, when the program can validate a single file.</p>



<h2 class="wp-block-heading">What I take away from Ansible 2.20</h2>



<ul class="wp-block-list"><li><strong>A <code>when:</code> must produce a real boolean.</strong> <code>-e key=value</code> always gives a string, so pass JSON or a file, or use <code>| bool</code> in the role;</li><li><strong>The new strictness catches a real bug.</strong> The string <code>"false"</code> used to evaluate as true;</li><li><strong>After a major ansible-core upgrade, run every playbook in <code>--check</code></strong>, including with targeted <code>--tags</code>, before trusting any deployment;</li><li><strong>Disk state and in-memory state can diverge</strong> when a run is interrupted: restart the affected services by hand, or use <code>force_handlers</code> or <code>flush_handlers</code>;</li><li><strong>Validate before installing.</strong> Otherwise <code>force_handlers</code> restarts a service with an invalid config.</li></ul>



<h2 class="wp-block-heading">Related articles</h2>



<ul class="wp-block-list"><li><a href="https://hecate.neurozone.fr/?p=102">CrowdSec 1.8 on Debian</a></li><li><a href="https://hecate.neurozone.fr/?p=2785">OpenBao without auto-unseal</a></li><li><a href="https://hecate.neurozone.fr/?p=1484">Finding every Node.js you run</a></li></ul>

<p>The post <a href="https://hecate.neurozone.fr/2026/12/02/ansible-2-20-gotchas-string-booleans-fact-gathering-lost-handlers/">Ansible 2.20 gotchas: string booleans from -e, tags that drop fact gathering, and lost handlers</a> appeared first on <a href="https://hecate.neurozone.fr">Hécate Regnier - Neurozone</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://hecate.neurozone.fr/2026/12/02/ansible-2-20-gotchas-string-booleans-fact-gathering-lost-handlers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2794</post-id>	</item>
	</channel>
</rss>
