<?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>Ansible Archives - Hécate Regnier - Neurozone</title>
	<atom:link href="https://hecate.neurozone.fr/tag/ansible/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>DBA, DevOps &#38; Sysadmin</description>
	<lastBuildDate>Mon, 02 Nov 2026 17:06:44 +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>Ansible 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>How-to: manage Pi-hole settings key by key, and its lists through the API</title>
		<link>https://hecate.neurozone.fr/2026/11/27/how-to-manage-pi-hole-settings-key-by-key-lists-api/</link>
					<comments>https://hecate.neurozone.fr/2026/11/27/how-to-manage-pi-hole-settings-key-by-key-lists-api/#respond</comments>
		
		<dc:creator><![CDATA[Hécate Regnier]]></dc:creator>
		<pubDate>Fri, 27 Nov 2026 09:00:00 +0000</pubDate>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[Sysadmin notebook]]></category>
		<category><![CDATA[Ansible]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Pi-hole]]></category>
		<guid isPermaLink="false">https://hecate.neurozone.fr/?p=3545</guid>

					<description><![CDATA[<p>Manage Pi-hole settings key by key with pihole-FTL --config, keep adlists in sync through the API, and avoid wiping the admin login.</p>
<p>The post <a href="https://hecate.neurozone.fr/2026/11/27/how-to-manage-pi-hole-settings-key-by-key-lists-api/">How-to: manage Pi-hole settings key by key, and its lists through the API</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">When I manage Pi-hole settings from code, I never push a whole configuration file. In this how-to, I manage Pi-hole settings key by key with <code>pihole-FTL --config</code>, and I keep adlists and allow or deny domains in sync through the API.</p>



<div class="quick-answer" style="background:#eef3fc;border-left:5px solid #4c7bd9;border-radius:4px;padding:16px 20px;margin:24px 0;color:#1f2937">
<p style="margin:0 0 8px"><strong>Quick answer</strong> — read, change and check one Pi-hole setting without touching the rest.</p>
<pre style="margin:0 0 8px;overflow:auto"><code>pihole-FTL --config database.maxDBdays       # read one setting
pihole-FTL --config database.maxDBdays 7     # write one setting (key value form)
pihole -g                                    # force a gravity (adlist) update</code></pre>
<p style="margin:0;font-size:0.9em">Details, explanations and checks follow below.</p>
</div>



<p class="wp-block-paragraph">Everything here comes from the Ansible role that configures my Pi-hole. The same ideas work with any tool, or by hand.</p>



<figure class="wp-block-image size-full"><a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/manage-pi-hole-settings-per-key_en.webp"><img fetchpriority="high" decoding="async" width="1720" height="560" src="https://hecate.neurozone.fr/wp-content/uploads/2026/11/manage-pi-hole-settings-per-key_en.webp" alt="Manage Pi-hole settings per key: a whole-file template wipes the login, pihole-FTL --config does not" class="wp-image-3544" srcset="https://hecate.neurozone.fr/wp-content/uploads/2026/11/manage-pi-hole-settings-per-key_en.webp 1720w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/manage-pi-hole-settings-per-key_en-300x98.webp 300w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/manage-pi-hole-settings-per-key_en-1024x333.webp 1024w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/manage-pi-hole-settings-per-key_en-768x250.webp 768w, https://hecate.neurozone.fr/wp-content/uploads/2026/11/manage-pi-hole-settings-per-key_en-1536x500.webp 1536w" sizes="(max-width: 800px) 100vw, 760px" /></a><figcaption class="wp-element-caption">Why I never template pihole.toml, and where the lists live.</figcaption></figure>



<h2 class="wp-block-heading">Before you start</h2>



<ul class="wp-block-list"><li>Pi-hole v6. Its configuration lives in <code>/etc/pihole/pihole.toml</code>.</li><li>A root shell on the Pi-hole host.</li><li>For the lists only: the admin password of the web interface, because the API asks for a session.</li></ul>



<h2 class="wp-block-heading">Why I never template the whole file</h2>



<p class="wp-block-paragraph">The file <code>/etc/pihole/pihole.toml</code> holds the password hashes of the web interface. They come from <code>pihole setpassword</code>, so a template cannot rebuild them. If my role wrote a whole file without them, the next restart of <code>pihole-FTL</code> would wipe the admin login.</p>



<p class="wp-block-paragraph">So the role sets each setting on its own with <code>pihole-FTL --config &lt;key&gt; &lt;value&gt;</code>. Pi-hole&#8217;s documentation gives the same form, <code>--config key.name value</code>, and says the command can do error checking for you.</p>



<h2 class="wp-block-heading">How to manage Pi-hole settings with pihole-FTL &#8211;config</h2>



<h3 class="wp-block-heading">Step 1: read the current value</h3>



<p class="wp-block-paragraph">First, I read the key. This is also the safest command to run on a live system.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">pihole-FTL --config database.maxDBdays</pre>



<h3 class="wp-block-heading">Step 2: write only what differs</h3>



<p class="wp-block-paragraph">Then I write the key, but only when the value differs. My role does this check for me. By hand, you read, compare, and write.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">pihole-FTL --config database.maxDBdays 7</pre>



<h3 class="wp-block-heading">Step 3: read it back</h3>



<p class="wp-block-paragraph">Finally, I spot-check the key after a real run. When I wrote the role, I verified the read path on my live Pi-hole, but I had not exercised the write path against production yet. So I run the role in check mode first, and I read the key back afterwards.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell">pihole-FTL --config database.maxDBdays</pre>



<h2 class="wp-block-heading">Manage adlists and allow or deny domains</h2>



<p class="wp-block-paragraph">The lists do not live in <code>pihole.toml</code>. Adlists and allow or deny domains live in the gravity database, <code>gravity.db</code>. So my role manages them through the local REST API: it opens a session on <code>/api/auth</code>, then works on <code>/api/lists</code> and <code>/api/domains</code>.</p>



<p class="wp-block-paragraph">The role is additive only. It creates the entries that gravity.db lacks, but it leaves alone the entries that my variables do not list. I built most of my allowlist and denylist by hand with Query Log, then Allow or Deny, in the web interface. A role cannot tell an entry I removed on purpose from one I never declared, so deleting automatically could unblock or reblock something. Instead, I prune stale entries by hand in the web interface and update my variables to match.</p>



<p class="wp-block-paragraph">Your Pi-hole serves the API documentation at <code>/api/docs</code>, matching your installed version.</p>



<p class="wp-block-paragraph">To force a refresh of the adlists, run <code>pihole -g</code>. The official installer already adds a weekly cron job for it, on Sundays around 03:57 with a random delay.</p>



<h2 class="wp-block-heading">Passwords: the trap I hit</h2>



<p class="wp-block-paragraph"><code>pihole setpassword</code> is not idempotent. It builds a new BALLOON-SHA256 hash with a fresh salt every time, so a tool cannot tell the same password from a new one.</p>



<p class="wp-block-paragraph">On 20 August 2026, I changed the password by hand and forgot to copy it to my secrets manager. The next day, the list management got a 401 on every real run. Because Pi-hole is the only host of that first play, the failure aborted all three plays, and I saw nothing in the dry runs.</p>



<p class="wp-block-paragraph">Since 28 September 2026, the read-only API calls also run in check mode, so a stale password now fails the dry run with a 401. The rule I follow: after a manual password change, I update the secrets manager the same day.</p>



<h2 class="wp-block-heading">Check that it worked</h2>



<ul class="wp-block-list"><li><code>pihole-FTL --config &lt;key&gt;</code> prints the value you wrote.</li><li>In check mode, the report lists exactly the list entries that a real run would add, because only the POST calls stay simulated.</li><li>The admin login still works after a restart of <code>pihole-FTL</code>.</li></ul>



<h2 class="wp-block-heading">If something goes wrong</h2>



<ul class="wp-block-list"><li>A 401 on every API call: the stored password and the live password diverged. Set the live password from your secrets manager again.</li><li><code>pihole deny --regex -l</code> shows zero entries while the database has some: on FTL v6.7, I saw this display quirk. I checked directly against <code>gravity.db</code> and the three regex entries blocked correctly.</li><li>Your admin login disappeared: a tool probably overwrote <code>pihole.toml</code> without the hashes. Set the password again with <code>pihole setpassword</code>.</li></ul>



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



<ul class="wp-block-list"><li>I manage Pi-hole settings key by key, because the file holds hashes that no template can rebuild.</li><li>I keep the lists additive, because my tool cannot know what I removed on purpose.</li><li>I sync every manual password change the same day, because the failure stays invisible until a real run.</li></ul>



<h2 class="wp-block-heading">Sources</h2>



<ul class="wp-block-list"><li><a href="https://docs.pi-hole.net/ftldns/configfile/">Pi-hole documentation: FTL configuration (pihole-FTL &#8211;config, pihole.toml)</a></li><li><a href="https://docs.pi-hole.net/api/">Pi-hole documentation: API (served on your own Pi-hole at /api/docs)</a></li><li>My own notes on the Ansible role that configures my Pi-hole.</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: leaving the distro package, the postinst trap and a protection checklist</a></li><li><a href="https://hecate.neurozone.fr/?p=596">How-to: the MariaDB settings that really matter, and how to check them</a></li><li><a href="https://hecate.neurozone.fr/?p=595">How-to: install and configure WireGuard between a server and home</a></li></ul>


<p>The post <a href="https://hecate.neurozone.fr/2026/11/27/how-to-manage-pi-hole-settings-key-by-key-lists-api/">How-to: manage Pi-hole settings key by key, and its lists through the API</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/11/27/how-to-manage-pi-hole-settings-key-by-key-lists-api/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3545</post-id>	</item>
	</channel>
</rss>
