<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="/feed.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2023-12-31T18:05:56+01:00</updated><id>/feed.xml</id><title type="html">eoli3n</title><subtitle>A blog that talks about Linux, BSD, Pizza, DevOps and more.</subtitle><entry><title type="html">Stop battery draining by Syncthing on Android</title><link href="/2021/12/29/syncthing-battery-draining.html" rel="alternate" type="text/html" title="Stop battery draining by Syncthing on Android" /><published>2021-12-29T00:00:00+01:00</published><updated>2021-12-29T00:00:00+01:00</updated><id>/2021/12/29/syncthing-battery-draining</id><content type="html" xml:base="/2021/12/29/syncthing-battery-draining.html">&lt;p&gt;In &lt;a href=&quot;/2021/12/21/degoogling-android.html&quot;&gt;degoogling&lt;/a&gt; post, I explained how I switch to CalyxOS. One great relief is that, as most google services are not running, I should expect a lower battery consumption and so, a longer battery life.&lt;br /&gt;
It was true, until I install Syncthing to sync my data between my devices instead of using centralized Google Drive.The service was draining my whole battery, beeing the only app which eat it.&lt;br /&gt;
As I rarely use Wifi networks, I need Syncthing to run over mobile data. The problem is that it runs in background, constantly checking for new data.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/easer/before.png&quot; alt=&quot;before&quot; width=&quot;300&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The main &lt;a href=&quot;https://f-droid.org/en/packages/com.nutomic.syncthingandroid/&quot;&gt;Syncthing&lt;/a&gt; app from f-droid, doesn’t provide much battery saving options.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;Syncthing Options / Disable RestartOnWakeUp&lt;/code&gt; : It is supposed to save battery, tried it without success.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;Running conditions / Disable run on battery&lt;/code&gt; : It would be a good solution if I could be able to force a run, even on battery, in emergency case.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href=&quot;https://f-droid.org/en/packages/com.github.catfriend1.syncthingandroid/&quot;&gt;Syncthing fork&lt;/a&gt; is supposed to be a better solution.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://github.com/Catfriend1/syncthing-android/tree/ed83b22596eb0b575cda7b3fd5b9a1c5704def14#readme&quot;&gt;README&lt;/a&gt; says that “Battery eater problem is fixed.”, so I &lt;a href=&quot;https://github.com/Catfriend1/syncthing-android/issues/870&quot;&gt;asked the dev&lt;/a&gt; for more explainations, his answer was a bit light.&lt;br /&gt;
Despite the fact that the fork gives some finer options to deal with battery consumption, it allowed me to save no more than 2 or 3 battery hours.&lt;/p&gt;

&lt;p&gt;The solution would be to sync only on specific conditions, to reduce the running syncing window. Luckily, Syncthing has an option to &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;Respect Android parameter about Data Syncing&lt;/code&gt;, and some automation tools exists.&lt;/p&gt;

&lt;h3 id=&quot;easer-automation-tool&quot;&gt;Easer automation tool&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://f-droid.org/fr/packages/ryey.easer/&quot;&gt;Easer&lt;/a&gt; is an Android event driven automation tool.&lt;br /&gt;
I want my sync to be disabled when the screen is locked. When the screen is unlocked, I want to limit sync to 1 min.&lt;br /&gt;
As my main concern is battery consumption, I want to always sync when battery is charging.&lt;br /&gt;
I usually charge at home, which is the only place where I use Wifi, lets trigger it then.&lt;/p&gt;

&lt;p&gt;Here’s my configuration.&lt;/p&gt;

&lt;h4 id=&quot;conditions&quot;&gt;Conditions&lt;/h4&gt;

&lt;p&gt;Conditions are long time events, based on states. I used it to check if the screen is unlocked or the battery is discharging.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/easer/conditions.png&quot; alt=&quot;conditions&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/easer/unlocked.png&quot; alt=&quot;unlocked&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/easer/charging.png&quot; alt=&quot;charging&quot; width=&quot;300&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;events&quot;&gt;Events&lt;/h4&gt;

&lt;p&gt;Events are what they are, short time changing states, used for exemple for timing.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/easer/events.png&quot; alt=&quot;events&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/easer/timing.png&quot; alt=&quot;timing&quot; width=&quot;300&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;profils&quot;&gt;Profils&lt;/h4&gt;

&lt;p&gt;Profils are set of actions.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/easer/profils.png&quot; alt=&quot;profils&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/easer/enable_sync.png&quot; alt=&quot;enable_sync&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/easer/disable_wifi.png&quot; alt=&quot;disable_wifi&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/easer/enable_sync_and_wifi.png&quot; alt=&quot;enable_sync_and_wifi&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/easer/disable_sync.png&quot; alt=&quot;disable_sync&quot; width=&quot;300&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;scripts&quot;&gt;Scripts&lt;/h4&gt;

&lt;p&gt;Scripts link events and conditions to profils.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/easer/scripts.png&quot; alt=&quot;scripts&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/easer/when_charging.png&quot; alt=&quot;when_charging&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/easer/when_not_charging.png&quot; alt=&quot;when_not_charging&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/easer/when_unlocked.png&quot; alt=&quot;when_unlocked&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/easer/disable_sync_when_locked.png&quot; alt=&quot;disable_sync_when_locked&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/easer/disable_sync_1min.png&quot; alt=&quot;disable_sync_1min&quot; width=&quot;300&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;pivot&quot;&gt;Pivot&lt;/h4&gt;

&lt;p&gt;This is the global algorithm.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/easer/pivot.png&quot; alt=&quot;pivot&quot; width=&quot;600&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;for-24-hours-to--5-days&quot;&gt;For 24 hours to … 5 days&lt;/h3&gt;

&lt;p&gt;After one night, here’s the estimated battery duration time. Syncthing doesn’t even appear in the list, which is normal because it was not syncing at all.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/easer/after.png&quot; alt=&quot;after&quot; width=&quot;300&quot; /&gt;&lt;/p&gt;</content><author><name></name></author><summary type="html">In degoogling post, I explained how I switch to CalyxOS. One great relief is that, as most google services are not running, I should expect a lower battery consumption and so, a longer battery life. It was true, until I install Syncthing to sync my data between my devices instead of using centralized Google Drive.The service was draining my whole battery, beeing the only app which eat it. As I rarely use Wifi networks, I need Syncthing to run over mobile data. The problem is that it runs in background, constantly checking for new data.</summary></entry><entry><title type="html">Degoogling</title><link href="/2021/12/21/degoogling-android.html" rel="alternate" type="text/html" title="Degoogling" /><published>2021-12-21T00:00:00+01:00</published><updated>2021-12-21T00:00:00+01:00</updated><id>/2021/12/21/degoogling-android</id><content type="html" xml:base="/2021/12/21/degoogling-android.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#apps&quot; id=&quot;markdown-toc-apps&quot;&gt;Apps&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#data&quot; id=&quot;markdown-toc-data&quot;&gt;Data&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#emails-contacts-and-agenda&quot; id=&quot;markdown-toc-emails-contacts-and-agenda&quot;&gt;Emails, contacts, and agenda&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#maps-and-navigation&quot; id=&quot;markdown-toc-maps-and-navigation&quot;&gt;Maps and navigation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#os&quot; id=&quot;markdown-toc-os&quot;&gt;OS&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#hardware&quot; id=&quot;markdown-toc-hardware&quot;&gt;Hardware&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#calyxos-installation&quot; id=&quot;markdown-toc-calyxos-installation&quot;&gt;CalyxOS installation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#security-configurations&quot; id=&quot;markdown-toc-security-configurations&quot;&gt;Security configurations&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#aurora-store&quot; id=&quot;markdown-toc-aurora-store&quot;&gt;Aurora store&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#shelter-isolation&quot; id=&quot;markdown-toc-shelter-isolation&quot;&gt;Shelter isolation&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#datura-firewall&quot; id=&quot;markdown-toc-datura-firewall&quot;&gt;Datura firewall&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#seedvault-backups&quot; id=&quot;markdown-toc-seedvault-backups&quot;&gt;SeedVault backups&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#a-good-move&quot; id=&quot;markdown-toc-a-good-move&quot;&gt;A good move&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As many users, Google trapped me many years ago, with my first Android smartphone. Google services are like cotton candy, sweet, colorful, comfortable, but abuse it and you ruin you health. Before even thinking about privacy, I want to be able to choose what services I run on my smartphone. Android version upgrades and the overlay of the manufacturer android rom is heavy and it makes any mid-range smartphone unusable in less than 2 years.&lt;br /&gt;
Another problem is that you can’t use Android without a google account.&lt;/p&gt;

&lt;p&gt;So I started degoogling, step by step, which was a one year trip…&lt;/p&gt;

&lt;h3 id=&quot;apps&quot;&gt;Apps&lt;/h3&gt;

&lt;p&gt;I started by trying to find FOSS alternatives for each apps I use.&lt;br /&gt;
&lt;a href=&quot;https://f-droid.org/&quot;&gt;F-droid&lt;/a&gt; is a application store for FOSS on Android and you can find some alternative on &lt;a href=&quot;https://degoogle.jmoore.dev/&quot;&gt;Degoogle&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here’s a cool app list :&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/com.github.axet.bookreader/&quot;&gt;Book Reader&lt;/a&gt; : Simple book reader&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/me.hackerchick.catima/&quot;&gt;Catima&lt;/a&gt; : Loyalty Card Wallet&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/ws.xsoh.etar/&quot;&gt;Etar Calendar&lt;/a&gt; : Agenda app which supports CalDav&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/eu.faircode.email/&quot;&gt;FairEmail&lt;/a&gt; : Fully featured email client. Neat, intuitive user interface. Privacy friendly&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/ml.docilealligator.infinityforreddit/&quot;&gt;Infinity&lt;/a&gt; : A beautiful, feature-rich Reddit client.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/org.documentfoundation.libreoffice/&quot;&gt;LibreOffice Viewer&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/net.gsantner.markor/&quot;&gt;Markor&lt;/a&gt; : Lightweight text editor, Markdown Notes &amp;amp; ToDo.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/com.artifex.mupdf.viewer.app/&quot;&gt;MuPDF&lt;/a&gt; : Minimalist PDF viewer&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/org.schabi.newpipe/&quot;&gt;NewPipe&lt;/a&gt; : Lightweight YouTube frontend&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/fr/packages/org.dslul.openboard.inputmethod.latin/&quot;&gt;OpenBoard&lt;/a&gt; : Look and feel of Gboard without the tracking&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/org.sufficientlysecure.keychain/&quot;&gt;OpenKeychain&lt;/a&gt; : GPG key manager&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/net.osmand.plus/&quot;&gt;OsmAnd&lt;/a&gt; : Map Viewing &amp;amp; Navigation for Offline and Online OSM Maps&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/dev.msfjarvis.aps/&quot;&gt;Password Store&lt;/a&gt; : Password Manager&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/net.typeblog.shelter/&quot;&gt;Shelter&lt;/a&gt; : Provides an isolated space that you can install or clone apps into&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/com.simplemobiletools.notes.pro/&quot;&gt;Simple Notes&lt;/a&gt; : Notes app with a clean widget&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/com.termux/&quot;&gt;Termux&lt;/a&gt; : Terminal emulator with packages&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://f-droid.org/en/packages/de.ph1b.audiobook/&quot;&gt;Voice&lt;/a&gt; : Simple audiobook reader&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;data&quot;&gt;Data&lt;/h3&gt;

&lt;p&gt;Google Drive allows you to access data on the cloud from any device. I used &lt;a href=&quot;https://rclone.org/&quot;&gt;rclone&lt;/a&gt; to be able to sync my data to a local storage. But Google still owns it too and its security is dependant to my Google account.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://syncthing.net/&quot;&gt;Syncthing&lt;/a&gt; is a open, trustworthy and decentralized file synchronization. You can install it on any OS, it’s easy to configure and fast.&lt;/p&gt;

&lt;p&gt;As you can sync any directory, I use it to sync my pictures to my nas and backup it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/degoogling/syncthing.png&quot; alt=&quot;syncthing&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;emails-contacts-and-agenda&quot;&gt;Emails, contacts, and agenda&lt;/h3&gt;

&lt;p&gt;Fashion is to end-to-end encryption services, like &lt;a href=&quot;https://protonmail.com/&quot;&gt;Protonmail&lt;/a&gt;, or &lt;a href=&quot;https://tutanota.com&quot;&gt;Tutanota&lt;/a&gt;.&lt;br /&gt;
Both of them are known backdoored, you can share encrypted mails only with users of the same service (if you don’t use gpg manually) and on Android, you need to use specific apps to access your synced contacts and agendas.&lt;br /&gt;
Some workaround are one the road, but I prefer more open solutions, because I don’t need that level of security.&lt;/p&gt;

&lt;p&gt;For mail hosting, I chose &lt;a href=&quot;runbox.com&quot;&gt;runbox.com&lt;/a&gt;. The &lt;a href=&quot;https://github.com/runbox/runbox7&quot;&gt;last version&lt;/a&gt; of the web app si open-source. It is hosted in Norway, which has a respectful privacy legislation, servers are powered with green energy, and it provides caldav sync for contacts and agendas.&lt;/p&gt;

&lt;p&gt;I use the f-droid app &lt;a href=&quot;https://f-droid.org/fr/packages/at.bitfire.davdroid/&quot;&gt;Davx5&lt;/a&gt; as Cal/Card Dav sync client.&lt;/p&gt;

&lt;h3 id=&quot;maps-and-navigation&quot;&gt;Maps and navigation&lt;/h3&gt;

&lt;p&gt;FOSS alternative for Google Maps is OsmAnd. I tried to switch for my daily use, and I quickly realized that google maps was not only a simple navigation service. I use it to find opening hours of shops, phone numbers, shop based on a “meta” search… OsmAnd is based on &lt;a href=&quot;https://www.openstreetmap.org/&quot;&gt;openstreetmap&lt;/a&gt; which is a great service, if you know the full (and well typed) address. Another problem is that route calculation is done on the device, so it doesn’t know for the traffic, accidents, etc. To be honest, I think Google Maps as I use it, cannot be replaced for now by a FOSS app, so I would continue to use it.&lt;/p&gt;

&lt;h3 id=&quot;os&quot;&gt;OS&lt;/h3&gt;

&lt;p&gt;The main alternative OS is &lt;a href=&quot;https://lineageos.org/&quot;&gt;LineageOS&lt;/a&gt;. It is shipped defaultly without Google services.&lt;br /&gt;
Google services has been reimplemented open-source by the &lt;a href=&quot;https://github.com/microg&quot;&gt;MicroG&lt;/a&gt; project.&lt;/p&gt;

&lt;p&gt;Many apps and features depends on Google services : mainly push notifications with GCM.&lt;br /&gt;
Sadly, I still need those services, to be able to use any app from the regular store.&lt;br /&gt;
You can check compatibility of apps without Google services with &lt;a href=&quot;https://plexus.techlore.tech/&quot;&gt;Plexus&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;LineageOS is great, but you need to find the right hardware to run it, and the hardware support is community-driven.&lt;br /&gt;
The flash process could be tricky, with a significant risk to brick your device.&lt;/p&gt;

&lt;p&gt;Here comes the funny part : The only choice that allows you to unlock the bootloader and install a custom ROM without too much effort/risk are Google phones because those are designed for developpers !&lt;/p&gt;

&lt;p&gt;Choosing a Google smartphone like a Pixel or a Nexus opens your choices to &lt;a href=&quot;https://grapheneos.org/&quot;&gt;GrapheneOS&lt;/a&gt; or &lt;a href=&quot;https://calyxos.org/&quot;&gt;CalyxOS&lt;/a&gt;. Both of them as based on &lt;a href=&quot;https://source.android.com/&quot;&gt;Android Open Source Project&lt;/a&gt;, which is Android without the Google commercial overlay.&lt;/p&gt;

&lt;p&gt;I will not compare those 2 here, but I chose CalyxOS for those features :&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Project driven by &lt;a href=&quot;https://calyxinstitute.org/&quot;&gt;Calyx Institute&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;MicroG included (and can be disabled)&lt;/li&gt;
  &lt;li&gt;Focused on privacy&lt;/li&gt;
  &lt;li&gt;Security with &lt;a href=&quot;https://calyxos.org/docs/tech/datura-details/&quot;&gt;Datura&lt;/a&gt; per app firewall&lt;/li&gt;
  &lt;li&gt;Auto backup with &lt;a href=&quot;https://calyxinstitute.org/projects/seedvault-encrypted-backup-for-android&quot;&gt;Seedvault&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To go further : &lt;a href=&quot;https://privacyguides.org/android/#aosp-derivatives&quot;&gt;privacyguides.org/android&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;hardware&quot;&gt;Hardware&lt;/h3&gt;

&lt;p&gt;I just switch to a 5G subscription, so the choice is pretty limited.&lt;br /&gt;
Despite the fact that the Google Pixel 6 is out since 4 month, I went for a Google Pixel 4a 5g, because it’s cheaper, the screen is smaller and it stills have a minijack :) I also wanted to be able to directly install CalyxOs without beeing stuck on the Google Pixel ROM. When I write those lines, CalyxOS doesn’t support Google Pixel 6 still.&lt;/p&gt;

&lt;h3 id=&quot;calyxos-installation&quot;&gt;CalyxOS installation&lt;/h3&gt;

&lt;p&gt;As said, a benefit for using a developer phone is that the flash procedure is pretty simple, and stressless.&lt;br /&gt;
You just need to download the flasher binary and the OS archive.&lt;br /&gt;
See &lt;a href=&quot;https://calyxos.org/install/devices/bramble/linux/&quot;&gt;Install on a Pixel 4a (5G)&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;On void linux, I needed to install some packages.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;xbps-install &lt;span class=&quot;nt&quot;&gt;-S&lt;/span&gt; android-tools android-udev-rules
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;At first, &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;device-flasher&lt;/code&gt; didn’t detect the smartphone.&lt;br /&gt;
I got help on IRC &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;libera.chat &lt;span class=&quot;c&quot;&gt;#calyxos&lt;/span&gt;&lt;/code&gt;, the community has been nice and helpful.&lt;br /&gt;
They adviced me to &lt;a href=&quot;https://calyxos.org/install/fastboot/&quot;&gt;boot it in fastboot mode&lt;/a&gt; and to run &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;device-flasher&lt;/code&gt; with sudo. It worked like a charm, 5 min and the phone rebooter under CalyxOS.&lt;/p&gt;

&lt;h3 id=&quot;security-configurations&quot;&gt;Security configurations&lt;/h3&gt;

&lt;h4 id=&quot;aurora-store&quot;&gt;Aurora store&lt;/h4&gt;

&lt;p&gt;After the first boot, a configuration menu let you enable &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;microG&lt;/code&gt; and it doesn’t ask you to attach a google account. To be able to install Play Store apps without account, it uses &lt;a href=&quot;https://aurora-store.fr.uptodown.com/android&quot;&gt;Aurora Store&lt;/a&gt;. It supports anonymous apk downloads and installations, and can silently auto upgrade for apps in background.&lt;/p&gt;

&lt;h4 id=&quot;shelter-isolation&quot;&gt;Shelter isolation&lt;/h4&gt;

&lt;p&gt;Those untrustable applications doesn’t need for the most part to be able to access my data, or network.&lt;br /&gt;
&lt;a href=&quot;https://f-droid.org/fr/packages/net.typeblog.shelter/&quot;&gt;Shelter&lt;/a&gt; use the Android work profile feature to allow you to isolate apps from your data, disabling the ability to use or leak you contacts, for exemple.&lt;/p&gt;

&lt;p&gt;To configure it, install &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;shelter&lt;/code&gt;, and use it to activate your work profile. Then you can clone &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;Aurora&lt;/code&gt; to the work profile, and use it from here to install untrusted apps.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/degoogling/shelter_clone_aurora.png&quot; alt=&quot;shelter&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/degoogling/work_profile.png&quot; alt=&quot;work&quot; width=&quot;300&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;datura-firewall&quot;&gt;Datura firewall&lt;/h4&gt;

&lt;p&gt;To isolate an app from network with &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;datura&lt;/code&gt;, start the app &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;firewall&lt;/code&gt; from the main profile.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/degoogling/datura_firewall.png&quot; alt=&quot;firewall&quot; width=&quot;300&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;seedvault-backups&quot;&gt;SeedVault backups&lt;/h4&gt;

&lt;p&gt;Start &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;Backup&lt;/code&gt; app and configure it to backup apps and its configurations on the local storage.&lt;br /&gt;
Encrypted backups will be stored in &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;~/.SeedVaultAndroidBackup&lt;/code&gt;.&lt;br /&gt;
Then I use &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;Syncthing&lt;/code&gt; to spread it on my nas which snapshots it on ZFS.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/degoogling/backup.png&quot; alt=&quot;backup&quot; width=&quot;300&quot; /&gt; &lt;img src=&quot;/assets/images/degoogling/backup_syncthing.png&quot; alt=&quot;backup_syncthing&quot; width=&quot;300&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;a-good-move&quot;&gt;A good move&lt;/h3&gt;

&lt;p&gt;For now, I didn’t face any issue, let’s see in daily use.&lt;br /&gt;
I still have many things to test :&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;CalyxOS provides two free VPNs by default, &lt;a href=&quot;https://calyxinstitute.org/projects/digital-services/vpn&quot;&gt;CalyxVPN&lt;/a&gt; and &lt;a href=&quot;https://calyxos.org/docs/guide/apps/riseup-vpn/&quot;&gt;Rise Up VPN&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;A default offline map app : &lt;a href=&quot;https://f-droid.org/fr/packages/app.organicmaps/&quot;&gt;Organic Maps&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;How &lt;a href=&quot;https://calyxos.org/docs/guide/security/location/&quot;&gt;location privacy&lt;/a&gt; works&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Over The Air upgrade to Android 12 is coming soon.&lt;/p&gt;

&lt;p&gt;For sure, it is a one way trip, may CalyxOS have a long life !&lt;/p&gt;</content><author><name></name></author><summary type="html"></summary></entry><entry><title type="html">Monitoring</title><link href="/2021/12/10/monitoring.html" rel="alternate" type="text/html" title="Monitoring" /><published>2021-12-10T00:00:00+01:00</published><updated>2021-12-10T00:00:00+01:00</updated><id>/2021/12/10/monitoring</id><content type="html" xml:base="/2021/12/10/monitoring.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#turnkey-solution--netdata&quot; id=&quot;markdown-toc-turnkey-solution--netdata&quot;&gt;Turnkey solution : Netdata&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#declarative-and-lightweight-solution--monit&quot; id=&quot;markdown-toc-declarative-and-lightweight-solution--monit&quot;&gt;Declarative and lightweight solution : Monit&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#web-server-monitoring&quot; id=&quot;markdown-toc-web-server-monitoring&quot;&gt;Web server monitoring&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I was searching for a lightweight monitoring solution for my single freebsd home server.&lt;br /&gt;
It should be able to get storage, cpu and memory metrics, look at file changes, check up my services and send alerts.&lt;/p&gt;

&lt;p&gt;I took a look at monitoring stacks like &lt;a href=&quot;https://play.grafana.org/d/000000029/prometheus-demo-dashboard?orgId=1&amp;amp;refresh=5m&quot;&gt;Prometheus-Node_exporter-Grafana&lt;/a&gt; or &lt;a href=&quot;https://www.influxdata.com/blog/introduction-to-influxdatas-influxdb-and-tick-stack/&quot;&gt;Telegraf-InfluxDB-Chronograf-Kapacitor&lt;/a&gt;. It looked like to me a rabbit hole, grafana dashboard is pretty, it does tons of things, but it can’t handle simplest of my needs. You still need &lt;a href=&quot;https://www.prometheus.io/docs/alerting/latest/alertmanager/&quot;&gt;AlertManager&lt;/a&gt; to send mails with your prometheus stack. Endless microservices chain…&lt;br /&gt;
Those are great solutions when managing large node/service farms.&lt;/p&gt;

&lt;h3 id=&quot;turnkey-solution--netdata&quot;&gt;Turnkey solution : Netdata&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://www.netdata.cloud/&quot;&gt;Netdata&lt;/a&gt; provides a nice dashboard with realtime metrics, and it supervises system health. It can raise a lot of alerts by default and mail it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/server/netdata.png&quot; alt=&quot;netdata&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I had to configure &lt;a href=&quot;https://github.com/corecode/dma&quot;&gt;DragonFly Mail Agent&lt;/a&gt; which is a small Mail Transfert Agent with SMTP authentication over TLS/SSL.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;/etc/dma/dma.conf&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SMARTHOST smtp.domain.com
PORT 587
AUTHPATH /etc/dma/auth.conf
SECURETRANSFER
STARTTLS
MAILNAME eoli3n.eu.org
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;/etc/dma/auth.conf&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mail@domain.com|smtp.domain.com:P@ssw0rd!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Let’s configure mail forwarding from root to external email&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;/etc/aliases&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;root: jonathan.kirszling@runbox.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I can now test netdata mail transfert by running a test script.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;/usr/local/libexec/netdata/plugins.d/alarm-notify.sh &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Out of the box, netdata checks metrics every seconds, and stores it to RAM with 2 days of retention. With htop, I have noticed 1.7% of CPU and 0.7% of RAM.&lt;br /&gt;
Following &lt;a href=&quot;https://learn.netdata.cloud/guides/configure/performance&quot;&gt;recommendations for performance&lt;/a&gt;, netdata dropped to 0.0% of CPU, 0.4% of RAM, with 2 weeks of metrics retention.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;/usr/local/etc/netdata/netdata.conf&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-diff highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; [global]
&lt;span class=&quot;gi&quot;&gt;+    memory mode = dbengine
+    page cache size = 32
+    dbengine multihost disk space = 256
&lt;/span&gt;&lt;span class=&quot;gd&quot;&gt;-    history = 86400
&lt;/span&gt;&lt;span class=&quot;gi&quot;&gt;+    update every = 5
+    debug log = none
+    error log = none
+    access log = none
&lt;/span&gt;
 [plugins]
     freebsd = yes

 [web]
     respect do not track policy = yes
     disconnect idle clients after seconds = 3600
     bind to = 127.0.0.1
     web files owner = netdata
     web files group = netdata
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Netdata seems to be clever, it checks a lots of things, but I would like a more declarative solution, to check and alert anything I need.&lt;/p&gt;

&lt;h3 id=&quot;declarative-and-lightweight-solution--monit&quot;&gt;Declarative and lightweight solution : Monit&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://mmonit.com/monit/&quot;&gt;Monit&lt;/a&gt; is a small utility for managing and monitoring processes, files, directories, filesystems, programs, scripts, hosts, system metrics… It conducts automatic maintenance and repair if you ask it to. It also embeed a clean WebUI to keep an eye on all monitored services.&lt;/p&gt;

&lt;p&gt;Simply install &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;monit&lt;/code&gt; through your package manager and start writing your &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;monitrc&lt;/code&gt; file.&lt;br /&gt;
Here the jinja template I wrote for my server, explained in comments. I don’t even need to over-comment it, because the &lt;a href=&quot;https://www.mmonit.com/monit/documentation/monit.html#THE-MONIT-CONTROL-FILE&quot;&gt;DSL syntax&lt;/a&gt; is human readable.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;log /var/log/monit.log

&lt;span class=&quot;c&quot;&gt;# Check every 30 seconds and delay 120s at start&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;daemon 30
    with start delay 120

&lt;span class=&quot;c&quot;&gt;# Enable WebUI and configure it&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;httpd
    port 8080
    use address 127.0.0.1
    allow localhost
    signature disable

&lt;span class=&quot;c&quot;&gt;# Recipient email for alerts&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;alert 

&lt;span class=&quot;c&quot;&gt;# Configure SMTP server to use to send alert.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Monit doesn&apos;t use system sendmail command.&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;mailserver  port 
    username &lt;span class=&quot;s2&quot;&gt;&quot;&quot;&lt;/span&gt; password &lt;span class=&quot;s2&quot;&gt;&quot;&quot;&lt;/span&gt; using ssl

&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;mail-format &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    from: Monit &amp;lt;monit@&amp;gt;
    reply-to: noreply@
    subject: &lt;span class=&quot;nv&quot;&gt;$ACTION&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$SERVICE&lt;/span&gt;
    message:
Date:        &lt;span class=&quot;nv&quot;&gt;$DATE&lt;/span&gt;
Service:     &lt;span class=&quot;nv&quot;&gt;$SERVICE&lt;/span&gt;
Event:       &lt;span class=&quot;nv&quot;&gt;$EVENT&lt;/span&gt;
Action:      &lt;span class=&quot;nv&quot;&gt;$ACTION&lt;/span&gt;
Description: &lt;span class=&quot;nv&quot;&gt;$DESCRIPTION&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Zpool health&lt;/span&gt;
check program zpool-status with path &lt;span class=&quot;s2&quot;&gt;&quot;/sbin/zpool status -x&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;status &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; 0 &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

&lt;span class=&quot;c&quot;&gt;# Check zpool usage with a custom script&lt;/span&gt;
check program usage-zroot with path &lt;span class=&quot;s2&quot;&gt;&quot;/tmp/zpool_usage.sh zroot&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;status &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; 0 &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert
check program usage-dpool with path &lt;span class=&quot;s2&quot;&gt;&quot;/tmp/zpool_usage.sh dpool&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;status &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; 0 &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert
check program scrub-zroot with path &lt;span class=&quot;s2&quot;&gt;&quot;/tmp/zpool_scrub.sh zroot&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;status &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; 0 &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert
check program scrub-dpool with path &lt;span class=&quot;s2&quot;&gt;&quot;/tmp/zpool_scrub.sh dpool&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;status &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; 0 &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

&lt;span class=&quot;c&quot;&gt;# Resources&lt;/span&gt;
check system localhost
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;memory usage &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 85% &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;3 cycles &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;loadavg &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;15min&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 4 &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;cpu usage &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 85% &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;3 cycles &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;swap usage &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 25% &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;3 cycles &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

&lt;span class=&quot;c&quot;&gt;# SSHD&lt;/span&gt;
check process sshd with pidfile /var/run/sshd.pid
    start program &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;/usr/sbin/service sshd start&quot;&lt;/span&gt;
    stop program &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;/usr/sbin/service sshd stop&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;failed port  protocol ssh &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;restart
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;changed pid &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert
check file sshd_config path /etc/ssh/sshd_config
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;changed md5 checksum &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

check file passwd path /etc/passwd
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;changed md5 checksum &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

&lt;span class=&quot;c&quot;&gt;# Jails&lt;/span&gt;
check program jails with path &lt;span class=&quot;s2&quot;&gt;&quot;/usr/local/bin/bastille list -a&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;content &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Down&quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

&lt;span class=&quot;c&quot;&gt;# Updates&lt;/span&gt;
check program updates with path &lt;span class=&quot;s2&quot;&gt;&quot;/usr/bin/awk &apos;/packages to be upgraded/ {v+=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$NF&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;}END{print v;if (v&amp;gt;=5) exit 1}&apos; /tmp/check-updates&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;status &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; 1 &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

&lt;span class=&quot;c&quot;&gt;# Audit&lt;/span&gt;
check program audit with path &lt;span class=&quot;s2&quot;&gt;&quot;/usr/bin/awk &apos;/found/ {v+=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;}END{print v;if (v&amp;gt;=5) exit 1}&apos; /tmp/bastille-audit&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;status &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; 1 &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

&lt;span class=&quot;c&quot;&gt;# Web&lt;/span&gt;
check process nginx with pidfile /usr/local/bastille/jails/nginx/root/var/run/nginx.pid
    start program &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;/usr/local/bin/bastille start nginx&quot;&lt;/span&gt;
    stop program  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;/usr/local/bin/bastille stop nginx&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;failed host photos.eoli3n.eu.org port 443 protocol https content &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Photos&quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;failed host eoli3n.eu.org port 443 protocol https content &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;… Blog …&quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

&lt;span class=&quot;c&quot;&gt;# DNS&lt;/span&gt;
check process nsd with pidfile /usr/local/bastille/jails/nsd/root/var/run/nsd/nsd.pid
    start program &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;/usr/local/bin/bastille start nsd&quot;&lt;/span&gt;
    stop program  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;/usr/local/bin/bastille stop nsd&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;failed host  port 53 use &lt;span class=&quot;nb&quot;&gt;type &lt;/span&gt;udp protocol dns &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;restart
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;changed pid &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

&lt;span class=&quot;c&quot;&gt;# Syncthing&lt;/span&gt;
check process syncthing with pidfile /usr/local/bastille/jails/syncthing/root/var/run/syncthing.pid
    start program &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;/usr/local/bin/bastille start syncthing&quot;&lt;/span&gt;
    stop program  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;/usr/local/bin/bastille stop syncthing&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;changed pid &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

&lt;span class=&quot;c&quot;&gt;# Backups&lt;/span&gt;
check directory backup-host1 path /data/zfs/backups/host1
   &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;timestamp &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 24 hour &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert
check directory backup-host2 path /data/zfs/backups/host2
   &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;timestamp &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 24 hour &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

&lt;span class=&quot;c&quot;&gt;# Snapshots&lt;/span&gt;
check directory zfs-snapshots-slash path /.zfs/snapshot
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;timestamp &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 2 hours &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

&lt;span class=&quot;c&quot;&gt;# Sigal&lt;/span&gt;
check file sigal-check path /tmp/sigal-check
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;changed md5 checksum &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert

&lt;span class=&quot;c&quot;&gt;# Jekyll&lt;/span&gt;
check directory jekyll path /data/zfs/www/blog
   &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;changed timestamp &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;zpool_usage.sh&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/sh&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;cap: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;zpool list &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; cap &lt;span class=&quot;nt&quot;&gt;-H&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; used: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;zpool list &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; alloc &lt;span class=&quot;nt&quot;&gt;-H&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; free: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;zpool list &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; free &lt;span class=&quot;nt&quot;&gt;-H&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; size: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;zpool list &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; size &lt;span class=&quot;nt&quot;&gt;-H&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;cap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;zpool list &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; cap &lt;span class=&quot;nt&quot;&gt;-H&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;tr&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;%&apos;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$cap&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-gt&lt;/span&gt; 90 &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;then
    &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;exit &lt;/span&gt;1
&lt;span class=&quot;k&quot;&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;zpool_scrub.sh&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/sh&lt;/span&gt;

&lt;span class=&quot;nv&quot;&gt;scrub_expire&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;3110400&quot;&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;# 36days * 24hours * 60minutes * 60seconds&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;current_date&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;/bin/date +%s&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;scrub&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;/sbin/zpool status &lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;grep &lt;/span&gt;scrub | &lt;span class=&quot;nb&quot;&gt;awk&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;{print $15 $12 $13}&apos;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;scrub_date&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;date&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;%Y%b%e-%H%M%S&apos;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$scrub&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;-000000&apos;&lt;/span&gt; +%s&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;/sbin/zpool status &lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;grep &lt;/span&gt;scrub&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;$((&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$current_date&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$scrub_date&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-ge&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$scrub_expire&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;then
    &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;exit &lt;/span&gt;1
&lt;span class=&quot;k&quot;&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then run &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;monit&lt;/code&gt;, and check http://localhost:8080. You will now receive a mail when a test fails !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/server/monit.png&quot; alt=&quot;monit&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;web-server-monitoring&quot;&gt;Web server monitoring&lt;/h3&gt;

&lt;p&gt;Next step is to monitor my web server. Netdata provides a way to &lt;a href=&quot;https://learn.netdata.cloud/docs/agent/collectors/quickstart/#configure-your-application-or-service-for-monitoring&quot;&gt;get real-time stats&lt;/a&gt; from &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;/nginx_status&lt;/code&gt;.&lt;br /&gt;
If you don’t use Netdata, &lt;a href=&quot;https://www.monitorix.org/&quot;&gt;monitorix&lt;/a&gt; could be a good alternative.&lt;/p&gt;

&lt;p&gt;Both of those are realtime, I prefer a solution with historization, which would parse &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;access.log&lt;/code&gt; to produce some graphs.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://goaccess.io/&quot;&gt;GoAccess&lt;/a&gt; can parse logs and do it realtime though its own websocket server, developed by the same guy. The tool is impressive, it can be used cli or generate a html report !&lt;/p&gt;

&lt;script id=&quot;asciicast-455413&quot; src=&quot;https://asciinema.org/a/455413.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;p&gt;To be able to consult the html report, I choose to generate it statically everyday with a cron and spread it with &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;Syncthing&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;generate reports everyday at midnight&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;cron&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;goaccess report&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;job&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/local/bin/goaccess&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/local/bastille/jails/nginx/root/var/log/nginx/access.log&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;--log-format=COMBINED&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-o&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/data/zfs/sync/docs/reports/nginx-goaccess.html&apos;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;hour&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;0&apos;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;minute&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;0&apos;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;root&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;From any client which has the file synced.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;firefox ~/share/docs/reports/nginx-goaccess.html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/server/goaccess.png&quot; alt=&quot;goaccess&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The site is responsive, I can also consult it with my smartphone.&lt;br /&gt;
To finish, let’s add a &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;monit&lt;/code&gt; service to check that the report is well generated everyday.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# GoAccess&lt;/span&gt;
check file goaccess path /data/zfs/sync/docs/reports/nginx-goaccess.html
    &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;timestamp &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 24 hours &lt;span class=&quot;k&quot;&gt;then &lt;/span&gt;alert
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The loop is closed.&lt;/p&gt;</content><author><name></name></author><summary type="html"></summary></entry><entry><title type="html">Managing FreeBSD Jails with Ansible - part 3</title><link href="/2021/06/14/jails-part-3.html" rel="alternate" type="text/html" title="Managing FreeBSD Jails with Ansible - part 3" /><published>2021-06-14T00:00:00+02:00</published><updated>2021-06-14T00:00:00+02:00</updated><id>/2021/06/14/jails-part-3</id><content type="html" xml:base="/2021/06/14/jails-part-3.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#network-role&quot; id=&quot;markdown-toc-network-role&quot;&gt;Network role&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#firewall-role&quot; id=&quot;markdown-toc-firewall-role&quot;&gt;Firewall role&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#jails-role&quot; id=&quot;markdown-toc-jails-role&quot;&gt;Jails role&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#install-and-configure-bastille&quot; id=&quot;markdown-toc-install-and-configure-bastille&quot;&gt;Install and configure Bastille&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#bootstrap-a-release&quot; id=&quot;markdown-toc-bootstrap-a-release&quot;&gt;Bootstrap a release&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#web-role&quot; id=&quot;markdown-toc-web-role&quot;&gt;Web role&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#prepare-the-nginx-template&quot; id=&quot;markdown-toc-prepare-the-nginx-template&quot;&gt;Prepare the nginx template&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#create-a-nginx-jail&quot; id=&quot;markdown-toc-create-a-nginx-jail&quot;&gt;Create a nginx jail&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#template-the-nginx-jail&quot; id=&quot;markdown-toc-template-the-nginx-jail&quot;&gt;Template the nginx jail&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#run-the-playbook&quot; id=&quot;markdown-toc-run-the-playbook&quot;&gt;Run the playbook&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#test-the-service&quot; id=&quot;markdown-toc-test-the-service&quot;&gt;Test the service&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the &lt;a href=&quot;/2021/06/09/jails-part-2.html&quot;&gt;second part&lt;/a&gt;, we adapted our Ansible project to manage Jails with vnet.&lt;br /&gt;
The two first posts was useful to understand basic Jail creation, let’s now wrap it with &lt;a href=&quot;https://github.com/BastilleBSD/bastille&quot;&gt;Bastille&lt;/a&gt;.&lt;br /&gt;
Bastille is the BSD Docker-like toolset for managing containers.&lt;br /&gt;
That solution has many advantages, it wraps useful &lt;a href=&quot;https://github.com/BastilleBSD/bastille#basic-usage&quot;&gt;commands&lt;/a&gt; to manage Jails without having to rewrite it with Ansible.&lt;br /&gt;
It also has a &lt;a href=&quot;https://github.com/BastilleBSD/bastille#bastille-template&quot;&gt;template&lt;/a&gt; feature to automate Jail provisionning.&lt;br /&gt;
The &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;template&lt;/code&gt; automate Jails creation with a &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;Bastillefile&lt;/code&gt;. Note the docker reference, even the syntax looks similar.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;So why wrapping Bastille with Ansible ?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Using Bastille let you provision a Jail easily, but it does not wrap Jails creation nor automate the configuration of your services. My goal is that Ansible manages automatically everything related to your service, if you need to update a config file or anything, just do it in your project and run &lt;em&gt;ansible-playbook&lt;/em&gt;, to deploy and restart everything properly.&lt;/p&gt;

&lt;p&gt;Following Bastille documentation, we will configure the server as if it was in DMZ, using &lt;a href=&quot;https://www.openbsd.org/faq/pf/&quot;&gt;pf&lt;/a&gt; as firewall to expose containers ports.&lt;/p&gt;

&lt;p&gt;Clean all roles in the Ansible project, and configurations on the server, from previous parts.&lt;br /&gt;
By the way, this post shows how Ansible is kind of auto documented, as each tasks has a name, the Ansible code is pretty clean to read, even if you don’t know the tool.&lt;/p&gt;

&lt;h3 id=&quot;network-role&quot;&gt;Network role&lt;/h3&gt;

&lt;p&gt;We need to match &lt;a href=&quot;https://github.com/BastilleBSD/bastille#network-requirements&quot;&gt;network requirements&lt;/a&gt;.&lt;br /&gt;
Create a &lt;em&gt;network&lt;/em&gt; role.&lt;br /&gt;
&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;meta: flush_handlers&lt;/code&gt; task triggers handlers without waiting the end of the play.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;roles/network/tasks/main.yml&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nn&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Add lo1 interface&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;community.general.sysrc&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;cloned_interfaces&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;value_present&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;lo1&quot;&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Name lo1 interface bastille0&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;community.general.sysrc&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ifconfig_lo1_name&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;bastille0&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;notify&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;netif cloneup&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;meta&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;flush_handlers&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;roles/network/handlers/main.yml&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nn&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;netif cloneup&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;shell&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;service netif cloneup&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;firewall-role&quot;&gt;Firewall role&lt;/h3&gt;

&lt;p&gt;Create a &lt;em&gt;firewall&lt;/em&gt; role.&lt;br /&gt;
&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;roles/firewall/tasks/main.yml&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nn&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;enable pf&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;community.general.sysrc&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;pf_enable&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;YES&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;notify&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;start pf&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;enable pflog&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;community.general.sysrc&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;pflog_enable&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;YES&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;notify&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;start pflog&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;template pf.conf&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;pf.conf.j2&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/etc/pf.conf&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;notify&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;reload pf&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;meta&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;flush_handlers&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;roles/firewall/templates/pf.conf.j2&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;ext_if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;{{ ansible_default_ipv4.interface }}&quot;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;### Default block policy is to return a reset packet&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;block-policy &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;### Reassemble fragmented packets&lt;/span&gt;
scrub &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;on &lt;span class=&quot;nv&quot;&gt;$ext_if&lt;/span&gt; all fragment reassemble
&lt;span class=&quot;c&quot;&gt;### Ignore loopback interface&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;skip on lo

&lt;span class=&quot;c&quot;&gt;### Allow empty table to exist&lt;/span&gt;
table &amp;lt;jails&amp;gt; persist
&lt;span class=&quot;c&quot;&gt;### Nat in jails table&lt;/span&gt;
nat on &lt;span class=&quot;nv&quot;&gt;$ext_if&lt;/span&gt; from &amp;lt;jails&amp;gt; to any -&amp;gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$ext_if&lt;/span&gt;:0&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;### Static rdr&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# rdr pass inet proto tcp from any to any port {80, 443} -&amp;gt; 10.17.89.45&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;### Enable dynamic rdr (see below)&lt;/span&gt;
rdr-anchor &lt;span class=&quot;s2&quot;&gt;&quot;rdr/*&quot;&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;### Block on incoming traffic&lt;/span&gt;
block &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;all
&lt;span class=&quot;c&quot;&gt;### Allow outgoing, skip others rules if match, and track connections&lt;/span&gt;
pass out quick keep state
&lt;span class=&quot;c&quot;&gt;### Block all incoming traffic from the $ext_if subnet which is not from $ext_if interface&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;### And block incoming traffic from $ext_if IP on $ext_if interface&lt;/span&gt;
antispoof &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$ext_if&lt;/span&gt; inet
&lt;span class=&quot;c&quot;&gt;### Allow SSH&lt;/span&gt;
pass &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;inet proto tcp from any to any port ssh flags S/SA keep state
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We use &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;async&lt;/code&gt; on &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;pf start&lt;/code&gt; handler to &lt;a href=&quot;https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html#avoid-connection-timeouts-poll-0&quot;&gt;keep ansible connection&lt;/a&gt; up.&lt;br /&gt;
For the &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;reload pf&lt;/code&gt; handler, we first test that the config file is valid with &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt;&lt;/code&gt; and apply the configuration only if it succeed.&lt;br /&gt;
&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;roles/firewall/handlers/main.yml&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nn&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;start pf&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;pf&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;started&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;45&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;poll&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;5&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;start pflog&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;pflog&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;started&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;reload pf&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;shell&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;pfctl -nf /etc/pf.conf &amp;amp;&amp;amp; pfctl -f /etc/pf.conf&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;jails-role&quot;&gt;Jails role&lt;/h3&gt;
&lt;h4 id=&quot;install-and-configure-bastille&quot;&gt;Install and configure Bastille&lt;/h4&gt;

&lt;p&gt;Create a role &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;jails&lt;/code&gt;.&lt;br /&gt;
Bastille will be configured to use ZFS.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;roles/jails/tasks/main.yml&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nn&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;install bastille&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;pkgng&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bastille&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;enable bastille&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;community.general.sysrc&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bastille_enable&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;YES&quot;&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;add bastille devfs rule&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;blockinfile&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/etc/devfs.rules&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;marker&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;lt;!--&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{mark}&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ANSIBLE&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;MANAGED&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;vnet&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;--&amp;gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;yes&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;block&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;|&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;[bastille_vnet=13]&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;add path &apos;bpf*&apos; unhide&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;enable zfs for bastille&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;community.general.sysrc&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;item.name&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;item.value&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/usr/local/etc/bastille/bastille.conf&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;bastille_zfs_enable&quot;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;YES&quot;&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;bastille_zfs_zpool&quot;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;zroot&quot;&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;bootstrap-a-release&quot;&gt;Bootstrap a release&lt;/h4&gt;

&lt;p&gt;Bootstrap the latest realease and configure it to use latest pkgs.&lt;br /&gt;
&lt;em&gt;Releases&lt;/em&gt; in Bastille is the template which will be use to layer up your jails.&lt;br /&gt;
So each configuration made to a release will be applied to all new jails created from this release.&lt;/p&gt;

&lt;p&gt;Add a var to &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;group_vars/all.yml&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;release&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;13.0-RELEASE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Then, add tasks to bootstrap the release from that var.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bootstrap {{ release }} release&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;shell&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;bastille&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;bootstrap&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;release&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;creates=&quot;/usr/local/bastille/releases/{{ release }}&quot;&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;configure bootstrap to use latest pkgs&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/local/bastille/releases/{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;release&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}/etc/pkg/FreeBSD.conf&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;regexp&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;^(.*)quarterly(.*)$&apos;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;\1latest\2&apos;&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;update bootstrap&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;shell&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;bastille&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;update&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;release&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;web-role&quot;&gt;Web role&lt;/h3&gt;
&lt;h4 id=&quot;prepare-the-nginx-template&quot;&gt;Prepare the nginx template&lt;/h4&gt;

&lt;p&gt;Create a role &lt;em&gt;nginx&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Here’s the interesting part. With a &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;Bastillefile&lt;/code&gt;, you automate your service provisionning.&lt;br /&gt;
Here we tell the template to install &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;nginx&lt;/code&gt; and enable it. Then we create our &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;/data/www&lt;/code&gt; dir in the jail, to bind the one from the host in it. We also overlay the nginx config file with &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;CP usr .&lt;/code&gt;. Finally we check if the config file is valid and then restart the service.&lt;br /&gt;
The &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;RDR&lt;/code&gt; line dynamically generate a rule for pf to redirect the http port from the host to the jail.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;roles/nginx/files/Bastillefile&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;PKG nginx
SYSRC &lt;span class=&quot;nv&quot;&gt;nginx_enable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;YES
CMD &lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; /data/www
CP usr &lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt;
CMD nginx &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt;
SERVICE nginx restart
FSTAB /data/www data/www nullfs ro 0 0
RDR tcp 80 80
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;roles/nginx/tasks/main.yml&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nn&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;create services template dir&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/local/bastille/templates/services/{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;role_name&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;directory&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;recurse&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;yes&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;copy template config files&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Bastillefile&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/local/bastille/templates/services/{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;role_name&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}/&quot;&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;create config path&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/local/bastille/templates/services/{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;role_name&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}/usr/local/etc/nginx/&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;directory&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;recurse&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;yes&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;copy config file&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;nginx.conf&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/local/bastille/templates/services/{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;role_name&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}/usr/local/etc/nginx/&quot;&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;create data/www dataset&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;community.general.zfs&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;zroot/www&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;present&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;extra_zfs_properties&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;mountpoint&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/data/www&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;roles/nginx/files/nginx.conf&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-conf highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;http&lt;/span&gt; {
    &lt;span class=&quot;n&quot;&gt;server&lt;/span&gt; {
        &lt;span class=&quot;n&quot;&gt;listen&lt;/span&gt;       &lt;span class=&quot;m&quot;&gt;80&lt;/span&gt;;
        &lt;span class=&quot;n&quot;&gt;server_name&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;localhost&lt;/span&gt;;

        &lt;span class=&quot;n&quot;&gt;location&lt;/span&gt; / {
            &lt;span class=&quot;n&quot;&gt;root&lt;/span&gt;   /&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;/&lt;span class=&quot;n&quot;&gt;www&lt;/span&gt;;
            &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;.&lt;span class=&quot;n&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;.&lt;span class=&quot;n&quot;&gt;htm&lt;/span&gt;;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Add the task to copy the website to the host dir, mounted in the jail.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;copy index.html&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;index.html&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/data/www/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;roles/nginx/files/index.html&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;A website without any JS !&lt;span class=&quot;nt&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;create-a-nginx-jail&quot;&gt;Create a nginx jail&lt;/h4&gt;

&lt;p&gt;We set, at jail creation, its static IP in any private subnet which differs from your gateway one, following the advice of the Bastille &lt;a href=&quot;https://github.com/BastilleBSD/bastille#tip-3&quot;&gt;README.md&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Pick any private address and be done with it. These are all isolated networks. In the end, what matters is you can map host:port to container:port reliably, and we can.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Add your Jail IP to &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;group_vars/all.yml&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;jails&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;nginx&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;10.0.0.1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;roles/nginx/tasks/main.yml&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;create jail&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;shell&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;bastille&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;role_name&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;release&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;jails[role_name]&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;creates&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/usr/local/bastille/jails/{{ role_name }}&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;start jail&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# https://github.com/BastilleBSD/bastille/issues/342&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;shell&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bastille start {{ role_name }} || &lt;/span&gt;&lt;span class=&quot;no&quot;&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;template-the-nginx-jail&quot;&gt;Template the nginx jail&lt;/h4&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;template jail&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;shell&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;bastille&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;role_name&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;services/{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;role_name&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;run-the-playbook&quot;&gt;Run the playbook&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible-playbook playbook.yml &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; network,firewall,jails,nginx

PLAY &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;k&quot;&gt;***************************************************************************************************&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Gathering Facts] &lt;span class=&quot;k&quot;&gt;*********************************************************************************************&lt;/span&gt;
ok: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;network : Add lo1 interface] &lt;span class=&quot;k&quot;&gt;*********************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;network : Name lo1 interface bastille0] &lt;span class=&quot;k&quot;&gt;**********************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;network : meta] &lt;span class=&quot;k&quot;&gt;**********************************************************************************************&lt;/span&gt;

RUNNING HANDLER &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;network : netif cloneup] &lt;span class=&quot;k&quot;&gt;**************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;firewall : &lt;span class=&quot;nb&quot;&gt;enable &lt;/span&gt;pf] &lt;span class=&quot;k&quot;&gt;****************************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;firewall : &lt;span class=&quot;nb&quot;&gt;enable &lt;/span&gt;pflog] &lt;span class=&quot;k&quot;&gt;*************************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;firewall : template pf.conf] &lt;span class=&quot;k&quot;&gt;*********************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;firewall : meta] &lt;span class=&quot;k&quot;&gt;*********************************************************************************************&lt;/span&gt;

RUNNING HANDLER &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;firewall : start pf] &lt;span class=&quot;k&quot;&gt;******************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

RUNNING HANDLER &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;firewall : start pflog] &lt;span class=&quot;k&quot;&gt;***************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

RUNNING HANDLER &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;firewall : reload pf] &lt;span class=&quot;k&quot;&gt;*****************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;bastille] &lt;span class=&quot;k&quot;&gt;************************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : &lt;span class=&quot;nb&quot;&gt;enable &lt;/span&gt;bastille] &lt;span class=&quot;k&quot;&gt;*************************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : add bastille devfs rule] &lt;span class=&quot;k&quot;&gt;*****************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : &lt;span class=&quot;nb&quot;&gt;enable &lt;/span&gt;zfs &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;bastille] &lt;span class=&quot;k&quot;&gt;*****************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;={&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;name&apos;&lt;/span&gt;: &lt;span class=&quot;s1&quot;&gt;&apos;bastille_zfs_enable&apos;&lt;/span&gt;, &lt;span class=&quot;s1&quot;&gt;&apos;value&apos;&lt;/span&gt;: &lt;span class=&quot;s1&quot;&gt;&apos;YES&apos;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;})&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;={&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;name&apos;&lt;/span&gt;: &lt;span class=&quot;s1&quot;&gt;&apos;bastille_zfs_zpool&apos;&lt;/span&gt;, &lt;span class=&quot;s1&quot;&gt;&apos;value&apos;&lt;/span&gt;: &lt;span class=&quot;s1&quot;&gt;&apos;zroot&apos;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;})&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : bootstrap 13.0-RELEASE release] &lt;span class=&quot;k&quot;&gt;**********************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : configure bootstrap to use latest pkgs] &lt;span class=&quot;k&quot;&gt;**************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : update bootstrap] &lt;span class=&quot;k&quot;&gt;************************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;nginx : create services template &lt;span class=&quot;nb&quot;&gt;dir&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;nginx : copy template config files] &lt;span class=&quot;k&quot;&gt;**************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;nginx : create config path] &lt;span class=&quot;k&quot;&gt;**********************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;nginx : copy config file] &lt;span class=&quot;k&quot;&gt;************************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;nginx : create data/www &lt;span class=&quot;nb&quot;&gt;dir&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;*********************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;nginx : copy index.html] &lt;span class=&quot;k&quot;&gt;*************************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;nginx : create jail] &lt;span class=&quot;k&quot;&gt;*****************************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;nginx : start jail] &lt;span class=&quot;k&quot;&gt;******************************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;nginx : template jail] &lt;span class=&quot;k&quot;&gt;***************************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

PLAY RECAP &lt;span class=&quot;k&quot;&gt;*********************************************************************************************************&lt;/span&gt;
host-test                  : &lt;span class=&quot;nv&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;26   &lt;span class=&quot;nv&quot;&gt;changed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;25   &lt;span class=&quot;nv&quot;&gt;unreachable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;failed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;skipped&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;rescued&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;ignored&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;test-the-service&quot;&gt;Test the service&lt;/h3&gt;

&lt;p&gt;From the server.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;curl http://10.0.0.1
&amp;lt;html&amp;gt;
  &amp;lt;p&amp;gt;A website without any JS &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&amp;lt;/p&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;From a client in the gateway subnet, if the &lt;em&gt;dynamic RDR&lt;/em&gt; worked, it should be reachable.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;curl http://192.168.0.100
&amp;lt;html&amp;gt;
  &amp;lt;p&amp;gt;A website without any JS &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&amp;lt;/p&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If your server is in your &lt;em&gt;DMZ&lt;/em&gt;, then your service in reachable from internet too.&lt;br /&gt;
You can now easily add new services by creating one role per service and use the nginx one as exemple.&lt;/p&gt;</content><author><name></name></author><summary type="html"></summary></entry><entry><title type="html">Managing FreeBSD Jails with Ansible - part 2</title><link href="/2021/06/09/jails-part-2.html" rel="alternate" type="text/html" title="Managing FreeBSD Jails with Ansible - part 2" /><published>2021-06-09T00:00:00+02:00</published><updated>2021-06-09T00:00:00+02:00</updated><id>/2021/06/09/jails-part-2</id><content type="html" xml:base="/2021/06/09/jails-part-2.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#clean-environment&quot; id=&quot;markdown-toc-clean-environment&quot;&gt;Clean environment&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#install-jib-script&quot; id=&quot;markdown-toc-install-jib-script&quot;&gt;Install jib script&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#configure-network-stack-in-jails&quot; id=&quot;markdown-toc-configure-network-stack-in-jails&quot;&gt;Configure network stack in jails&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#configure-epair-interface-in-jails-template&quot; id=&quot;markdown-toc-configure-epair-interface-in-jails-template&quot;&gt;Configure epair interface in jails template&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#run-the-playbook-and-test-connectivity&quot; id=&quot;markdown-toc-run-the-playbook-and-test-connectivity&quot;&gt;Run the playbook and test connectivity&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the &lt;a href=&quot;/2021/06/08/jails-part-1.html&quot;&gt;first part&lt;/a&gt;, we created the Ansible project to manage Jails with shared IP. In this post, we will adapt our playbook to create &lt;a href=&quot;https://www.unix.com/man-page/freebsd/9/vimage/&quot;&gt;vnet&lt;/a&gt; jails.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;vnet&lt;/code&gt; gives to jails their own network stacks. Each Jail will have a specific network interface with &lt;a href=&quot;https://www.freebsd.org/cgi/man.cgi?query=epair&amp;amp;sektion=4&amp;amp;manpath=freebsd-release-ports&quot;&gt;epair&lt;/a&gt; connected to a &lt;a href=&quot;https://www.freebsd.org/cgi/man.cgi?query=bridge&amp;amp;sektion=4&amp;amp;manpath=freebsd-release-ports&quot;&gt;bridge&lt;/a&gt;. Let’s quote something I read in a forum which resume well how it works:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Analogous to a physical network, a bridge interface works like a software switch, an epair works like a virtual network cable and a jail acts as a virtual computer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The bridge creation will be automated with &lt;a href=&quot;https://github.com/freebsd/freebsd-src/blob/373ffc62c158e52cde86a5b934ab4a51307f9f2e/share/examples/jails/jib&quot;&gt;jib&lt;/a&gt; script.&lt;br /&gt;
Let’s adapt our playbook to create that kind of jail networking.&lt;/p&gt;

&lt;p&gt;There is only few steps, but before all, reset our first configurations.&lt;/p&gt;

&lt;h3 id=&quot;clean-environment&quot;&gt;Clean environment&lt;/h3&gt;

&lt;p&gt;Remove the task which creates aliases, and remove them from your system.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; shell &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;service jail stop bind &amp;amp;&amp;amp; service jail stop nginx&quot;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; lineinfile &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;path=/etc/rc.conf regexp=&quot;.*alias.*&quot; state=absent&apos;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; file &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;path=/etc/jail.conf state=absent&apos;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; zfs &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;name=zroot/jails/bind state=absent&apos;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; zfs &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;name=zroot/jails/nginx state=absent&apos;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; raw &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;service netif restart&quot;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; raw &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;service routing restart&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;install-jib-script&quot;&gt;Install jib script&lt;/h3&gt;
&lt;p&gt;Add a task to copy the script in your &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;span class=&quot;nv&quot;&gt;$path&lt;/span&gt;&lt;/code&gt; with execution perms.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;install jib script&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/usr/share/examples/jails/jib&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/usr/local/bin/&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;remote_src&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;yes&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0755&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;configure-network-stack-in-jails&quot;&gt;Configure network stack in jails&lt;/h3&gt;
&lt;p&gt;At jail startup, &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;jib&lt;/code&gt; will create a bridge if non existent, create epairs and automatically attach them to the bridge. Stopping the jail will destroy interfaces but not the bridge.&lt;br /&gt;
Let’s change our task to declare to use that script in &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;exec.prestart&lt;/code&gt; and &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;exec.poststop&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;language-diff highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; - name: declare jails
&lt;span class=&quot;gd&quot;&gt;-  vars:
-    alias_ip: &quot;{{ inet | ipmath(ansible_loop.index) }}&quot;
&lt;/span&gt;   blockinfile:
     path: /etc/jail.conf
     marker: &quot;# {mark} ANSIBLE MANAGED: {{ item }}&quot;
     block: |
       {{ item }} {
           host.hostname = &quot;{{ item }}.domain.local&quot;;
           path = &quot;/usr/local/jails/{{ item }}&quot;;
           exec.consolelog = &quot;/var/log/jail_{{ item }}.log&quot;;
&lt;span class=&quot;gd&quot;&gt;-          ip4.addr = {{ alias_ip }};
&lt;/span&gt;&lt;span class=&quot;gi&quot;&gt;+          vnet;
+          vnet.interface = &quot;e0b_{{ item }}&quot;;
+          exec.prestart += &quot;jib addm {{ item }} {{ ansible_default_ipv4.interface }}&quot;;
+          exec.poststop += &quot;jib destroy {{ item }}&quot;;
&lt;/span&gt;       }
   loop: &quot;{{ jails | sort | flatten(levels=1) }}&quot;
&lt;span class=&quot;gd&quot;&gt;-  loop_control:
-    extended: yes
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;configure-epair-interface-in-jails-template&quot;&gt;Configure epair interface in jails template&lt;/h3&gt;
&lt;p&gt;Edit the bsdinstall template to add epair interface configuration and default gateway.&lt;/p&gt;
&lt;div class=&quot;language-diff highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; - name: template bsdinstall script
&lt;span class=&quot;gi&quot;&gt;+  vars:
+    jail_ip: &quot;{{ inet | ipmath(ansible_loop.index) }}&quot;
&lt;/span&gt;   copy:
     dest: &quot;/usr/local/jails/{{ item }}.template&quot;
     content: |
       DISTRIBUTIONS=&quot;base.txz&quot;
       export nonInteractive=&quot;YES&quot;
       #!/bin/sh
       sysrc sshd_enable=&quot;YES&quot;
&lt;span class=&quot;gi&quot;&gt;+      sysrc ifconfig_e0b_{{ item }}=&quot;inet {{ jail_ip }} netmask 255.255.255.0&quot;
+      sysrc defaultrouter=&quot;{{ gateway }}&quot;
&lt;/span&gt;       pkg install -y python37
       mkdir /root/.ssh
       chmod 600 /root/.ssh
   loop: &quot;{{ jails | sort | flatten(levels=1) }}&quot;
&lt;span class=&quot;gi&quot;&gt;+  loop_control:
+    extended: yes
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;run-the-playbook-and-test-connectivity&quot;&gt;Run the playbook and test connectivity&lt;/h3&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible-playbook playbook.yml
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;...]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : create zfs per jail dataset] &lt;span class=&quot;k&quot;&gt;***************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : template bsdinstall script] &lt;span class=&quot;k&quot;&gt;****************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : bsdinstall jails] &lt;span class=&quot;k&quot;&gt;**************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : authorize your ssh key] &lt;span class=&quot;k&quot;&gt;********************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : permit root login] &lt;span class=&quot;k&quot;&gt;*************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : &lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;default jails config] &lt;span class=&quot;k&quot;&gt;******************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : &lt;span class=&quot;nb&quot;&gt;declare &lt;/span&gt;jails] &lt;span class=&quot;k&quot;&gt;*****************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : start jails at startup] &lt;span class=&quot;k&quot;&gt;********************************************&lt;/span&gt;
ok: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : start jails] &lt;span class=&quot;k&quot;&gt;*******************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

PLAY RECAP &lt;span class=&quot;k&quot;&gt;***********************************************************************&lt;/span&gt;
host-test                  : &lt;span class=&quot;nv&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;11   &lt;span class=&quot;nv&quot;&gt;changed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;8    &lt;span class=&quot;nv&quot;&gt;unreachable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;failed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;skipped&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;rescued&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;ignored&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;jib&lt;/code&gt; created a bridge and attached jails interfaces in it.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; shell &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;ifconfig vtnet0bridge | grep member&quot;&lt;/span&gt;
host-test | CHANGED | &lt;span class=&quot;nv&quot;&gt;rc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0 &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;
	member: e0a_nginx &lt;span class=&quot;nv&quot;&gt;flags&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;143&amp;lt;LEARNING,DISCOVER,AUTOEDGE,AUTOPTP&amp;gt;
	member: e0a_bind &lt;span class=&quot;nv&quot;&gt;flags&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;143&amp;lt;LEARNING,DISCOVER,AUTOEDGE,AUTOPTP&amp;gt;
	member: vtnet0 &lt;span class=&quot;nv&quot;&gt;flags&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;143&amp;lt;LEARNING,DISCOVER,AUTOEDGE,AUTOPTP&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Let’s check if jails are running.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; shell &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;jls&quot;&lt;/span&gt;
host-test | CHANGED | &lt;span class=&quot;nv&quot;&gt;rc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0 &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;
   JID  IP Address      Hostname                      Path
     3                  bind.domain.local             /usr/local/jails/bind
     4                  nginx.domain.local            /usr/local/jails/nginx

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;As IP is configured in the Jail, host doesn’t know which one it is.&lt;br /&gt;
&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;e0b_&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;/code&gt; interfaces are attached to jails.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; shell &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;jexec bind ifconfig | grep e0b&quot;&lt;/span&gt;
host-test | CHANGED | &lt;span class=&quot;nv&quot;&gt;rc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0 &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;
e0b_bind: &lt;span class=&quot;nv&quot;&gt;flags&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;8843&amp;lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&amp;gt; metric 0 mtu 1500

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; shell &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;jexec nginx ifconfig | grep e0b&quot;&lt;/span&gt;
host-test | CHANGED | &lt;span class=&quot;nv&quot;&gt;rc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0 &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;
e0b_nginx: &lt;span class=&quot;nv&quot;&gt;flags&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;8843&amp;lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&amp;gt; metric 0 mtu 1500
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible &lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;:nginx &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; ping
nginx | SUCCESS &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;&quot;ansible_facts&quot;&lt;/span&gt;: &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;s2&quot;&gt;&quot;discovered_interpreter_python&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;/usr/local/bin/python3.7&quot;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;,
    &lt;span class=&quot;s2&quot;&gt;&quot;changed&quot;&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;,
    &lt;span class=&quot;s2&quot;&gt;&quot;ping&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;pong&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt; | SUCCESS &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;&quot;ansible_facts&quot;&lt;/span&gt;: &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;s2&quot;&gt;&quot;discovered_interpreter_python&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;/usr/local/bin/python3.7&quot;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;,
    &lt;span class=&quot;s2&quot;&gt;&quot;changed&quot;&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;,
    &lt;span class=&quot;s2&quot;&gt;&quot;ping&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;pong&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Jails are now exposed on my private subnet with their own network stack and reachable by Ansible.&lt;/p&gt;

&lt;p&gt;We learned how to automate shared IP and vnet Jails provisionning with Ansible.&lt;br /&gt;
Managing Jails is more than just provision it, you’ll need to maintain it, by upgrading packages or releases.&lt;br /&gt;
In the network side, you would use a private subnet to isolate your jails from your local private subnet, and NAT to have the abilitiy to allow/deny access, or forward a port to the right Jail.&lt;/p&gt;

&lt;p&gt;Full raw Ansible management is possible, but there already exists some clever wrapper with great features, like &lt;a href=&quot;https://github.com/cbsd/cbsd&quot;&gt;cbsd&lt;/a&gt;, &lt;a href=&quot;https://github.com/iocage/iocage&quot;&gt;iocage&lt;/a&gt;, or &lt;a href=&quot;https://github.com/BastilleBSD/bastille&quot;&gt;bastille&lt;/a&gt;.&lt;br /&gt;
In the &lt;a href=&quot;/2021/06/14/jails-part-3.html&quot;&gt;next part&lt;/a&gt;, I’ll focus on &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;bastille&lt;/code&gt; and how to automate our jails management with it, still wrapped by Ansible.&lt;/p&gt;</content><author><name></name></author><summary type="html"></summary></entry><entry><title type="html">Managing FreeBSD Jails with Ansible - part 1</title><link href="/2021/06/08/jails-part-1.html" rel="alternate" type="text/html" title="Managing FreeBSD Jails with Ansible - part 1" /><published>2021-06-08T00:00:00+02:00</published><updated>2021-06-08T00:00:00+02:00</updated><id>/2021/06/08/jails-part-1</id><content type="html" xml:base="/2021/06/08/jails-part-1.html">&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#init-ansible&quot; id=&quot;markdown-toc-init-ansible&quot;&gt;Init Ansible&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#create-project-and-configure&quot; id=&quot;markdown-toc-create-project-and-configure&quot;&gt;Create project and configure&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#make-your-project-configurable&quot; id=&quot;markdown-toc-make-your-project-configurable&quot;&gt;Make your project configurable&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#prepare-the-jails-host&quot; id=&quot;markdown-toc-prepare-the-jails-host&quot;&gt;Prepare the jails host&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#shared-ip-jail&quot; id=&quot;markdown-toc-shared-ip-jail&quot;&gt;Shared IP Jail&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#configure-ip-aliases&quot; id=&quot;markdown-toc-configure-ip-aliases&quot;&gt;Configure IP aliases&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#provision-jails-environments&quot; id=&quot;markdown-toc-provision-jails-environments&quot;&gt;Provision jails environments&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#declare-your-jails&quot; id=&quot;markdown-toc-declare-your-jails&quot;&gt;Declare your jails&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#run-and-test&quot; id=&quot;markdown-toc-run-and-test&quot;&gt;Run and test&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When it comes to manage an OS configuration, I always fully automate the process, it is a oneshot work, you write it, test it, forget it, until you need to modify the process. I kind of use Ansible to make the work concrete as I use my blog to clarify my ideas.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.freebsd.org/en/books/handbook/jails/&quot;&gt;Jails&lt;/a&gt; are like containers for FreeBSD, it lets you isolate your services from each others. Each Jail has its own IP, there are different ways to manage networking, let’s explore automation for each.&lt;/p&gt;

&lt;h3 id=&quot;init-ansible&quot;&gt;Init Ansible&lt;/h3&gt;

&lt;h4 id=&quot;create-project-and-configure&quot;&gt;Create project and configure&lt;/h4&gt;
&lt;p&gt;Create your Ansible project root and git it.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;mkdir &lt;/span&gt;jails &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;jails
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git init
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;mkdir &lt;/span&gt;roles group_vars
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Create inventory, if your host is configured with DHCP, check its IP.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;host-test ansible_host=192.168.0.44&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; hosts
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Configure Ansible.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;EOF&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt; &amp;gt; ansible.cfg
[defaults]
stdout_callback = yaml
inventory = hosts
remote_user = root
interpreter_python = auto_silent
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And create the playbook, with a role &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;jails&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;EOF&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt; &amp;gt; playbook.yml
---
- hosts: host-test
  roles:
    - { role: jails, tags: jails }
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF

&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; roles/jails/tasks
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Install &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;community.general&lt;/code&gt; collection, it contains &lt;a href=&quot;https://docs.ansible.com/ansible/latest/collections/community/general/sysrc_module.html&quot;&gt;sysrc&lt;/a&gt; ansible module to safely edit &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;rc.conf&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible-galaxy collection &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;community.general
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;make-your-project-configurable&quot;&gt;Make your project configurable&lt;/h4&gt;
&lt;p&gt;Add a configuration file as &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;group_vars/all.yml&lt;/code&gt;, with 3 vars. We will increment the static IP of the host in tasks, so choose an IP which can be incremented as many time as you have jails.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;inet&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;192.168.0.100&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;netmask&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;255.255.255.0&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;gateway&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;192.168.0.254&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;prepare-the-jails-host&quot;&gt;Prepare the jails host&lt;/h4&gt;
&lt;p&gt;Bootstrap &lt;a href=&quot;https://docs.ansible.com/ansible/latest/user_guide/intro_bsd.html#bootstrapping-bsd&quot;&gt;FreeBSD for Ansible&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; raw &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;pkg install -y python37&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Configure your default network interface.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; sysrc &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;name=&quot;ifconfig_{{ ansible_default_ipv4.interface }}&quot; value=&quot;inet {{ inet }} netmask {{ netmask }}&quot;&apos;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; sysrc &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;name=&quot;defaultrouter&quot; value=&quot;{{ gateway }}&quot;&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Restart &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;netif&lt;/code&gt; and &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;routing&lt;/code&gt; services to read you network configuration for &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;rc.conf&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; raw &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;service netif restart&quot;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; raw &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;service routing restart&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Adapt your inventory with the new static IP and you’re ready.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;host-test ansible_host=192.168.0.100&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; hosts
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;shared-ip-jail&quot;&gt;Shared IP Jail&lt;/h3&gt;

&lt;p&gt;The simpler way to create a Jail is to add IP alias to you network interface and then bind that IP to your Jail.&lt;br /&gt;
For the exemple, let’s create 2 jails, &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;/code&gt; and &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;nginx&lt;/code&gt;.&lt;br /&gt;
First we need to create two IP aliases, default IP is incremented with &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;ipmath&lt;/code&gt; which needs &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;netaddr&lt;/code&gt; python package installed on the controller.&lt;/p&gt;

&lt;p&gt;Let’s declare our jails in a list in &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;group_vars/all.yml&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;jails&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bind&lt;/span&gt;
  &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;nginx&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;configure-ip-aliases&quot;&gt;Configure IP aliases&lt;/h4&gt;
&lt;p&gt;We use &lt;a href=&quot;https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#extended-loop-variables&quot;&gt;extended loop vars&lt;/a&gt; to increment &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;inet&lt;/code&gt; IP with &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;ipmath&lt;/code&gt; which needs &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;netaddr&lt;/code&gt; python package installed on the controller. &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;ansible_loop.index0&lt;/code&gt; starts index at &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;0&lt;/code&gt; instead of &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;1&lt;/code&gt;.&lt;br /&gt;
To be sure that the list will always be processed in the same order, it needs to be explicitly sorted.&lt;/p&gt;

&lt;p&gt;In &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;roles/jails/tasks/main.yml&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nn&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;create IP aliases for jails&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;vars&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;alias_ip&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;inet&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ipmath(ansible_loop.index)&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;community.general.sysrc&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ifconfig_{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ansible_default_ipv4.interface&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}_alias{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ansible_loop.index0&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;inet&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;alias_ip&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;netmask&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;netmask&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;jails&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;flatten(levels=1)&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;loop_control&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;extended&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;yes&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;notify&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;restart netif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You need a handler to trigger the &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;netif&lt;/code&gt; service restart on configuration update.&lt;/p&gt;

&lt;p&gt;In &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;roles/jails/handlers/main.yml&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nn&quot;&gt;---&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;restart netif&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;netif&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;restarted&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Run your playbook, and test.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible-playbook playbook.yml

PLAY &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;k&quot;&gt;***************************************************************************************************&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Gathering Facts] &lt;span class=&quot;k&quot;&gt;*********************************************************************************************&lt;/span&gt;
ok: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;network : create IP aliases &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;jails] &lt;span class=&quot;k&quot;&gt;***********************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

RUNNING HANDLER &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;network : restart netif] &lt;span class=&quot;k&quot;&gt;**************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

PLAY RECAP &lt;span class=&quot;k&quot;&gt;*********************************************************************************************************&lt;/span&gt;
host-test                  : &lt;span class=&quot;nv&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;3    &lt;span class=&quot;nv&quot;&gt;changed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;2    &lt;span class=&quot;nv&quot;&gt;unreachable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;failed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;skipped&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;rescued&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;ignored&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Your host now has two aliases configured.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; shell &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;ifconfig vtnet0 | grep inet&quot;&lt;/span&gt;
host-test | CHANGED | &lt;span class=&quot;nv&quot;&gt;rc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0 &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;
	inet 192.168.0.100 netmask 0xffffff00 broadcast 192.168.0.255
	inet 192.168.0.101 netmask 0xffffff00 broadcast 192.168.0.255
	inet 192.168.0.102 netmask 0xffffff00 broadcast 192.168.0.255
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;provision-jails-environments&quot;&gt;Provision jails environments&lt;/h4&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;create zfs jails dataset&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;community.general.zfs&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;zroot/jails&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;present&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;extra_zfs_properties&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;mountpoint&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/usr/local/jails&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;create zfs per jail dataset&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;community.general.zfs&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;zroot/jails/{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;present&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;jails&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;flatten(levels=1)&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Install FreeBSD on the jails with a custom &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;bsdinstall&lt;/code&gt; script.&lt;br /&gt;
I faced an issue here, &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;bsdinstall&lt;/code&gt; uses its &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;jail&lt;/code&gt; argument to target the specific environment, and its &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;script&lt;/code&gt; argument to automate the process. Using both make it ignore the second one.&lt;/p&gt;

&lt;p&gt;I improved the &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;jail&lt;/code&gt; script to be able to use a &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;SCRIPT&lt;/code&gt; env var with the script path, to automate in jail provisionning and &lt;a href=&quot;https://github.com/freebsd/freebsd-src/pull/473&quot;&gt;created a PR&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now let’s create templates for automated provisionning.&lt;br /&gt;
Let’s install python3 and enable &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;sshd&lt;/code&gt; to be able to use Ansible on our jails.&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;template bsdinstall script&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/local/jails/{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}.template&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;|&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;DISTRIBUTIONS=&quot;base.txz&quot;&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;export nonInteractive=&quot;YES&quot;&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;#!/bin/sh&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;pkg install -y python37&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;sysrc sshd_enable=&quot;YES&quot;&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;mkdir /root/.ssh&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;chmod 600 /root/.ssh&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;jails&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;flatten(levels=1)&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Trigger the provisionning with the &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;shell&lt;/code&gt; module and &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;args: creates:&lt;/code&gt; to make it idempotent.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bsdinstall jails&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;shell&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;bsdinstall jail /usr/local/jails/&quot;{{ item }}&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;SCRIPT&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/local/jails/{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}.template&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;creates&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/local/jails/{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}/bin&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;jails&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;flatten(levels=1)&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Authorize your ssh public key in jails.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;authorize your ssh key&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;~/.ssh/id_rsa.pub&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/local/jails/{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}/root/.ssh/authorized_keys&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0600&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;jails&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;flatten(levels=1)&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We finally need to permit root login.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;permit root login&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/local/jails/{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}/etc/ssh/sshd_config&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;regexp&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;^#(PermitRootLogin).*&apos;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;\1&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;yes&apos;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;jails&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;flatten(levels=1)&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;declare-your-jails&quot;&gt;Declare your jails&lt;/h4&gt;
&lt;p&gt;Last thing we need is to declare jails in &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;/etc/jail.conf&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;set default jails config&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;blockinfile&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/etc/jail.conf&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;yes&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;marker&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{mark}&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ANSIBLE&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;MANAGED:&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;default&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;block&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;|&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;exec.start = &quot;/bin/sh /etc/rc&quot;;&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;exec.stop = &quot;/bin/sh /etc/rc.shutdown&quot;;&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;exec.clean;&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;mount.devfs;&lt;/span&gt;

&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;declare jails&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;vars&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;alias_ip&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;inet&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ipmath(ansible_loop.index)&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;blockinfile&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/etc/jail.conf&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;marker&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{mark}&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ANSIBLE&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;MANAGED:&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;block&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;|&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;{{ item }} {&lt;/span&gt;
          &lt;span class=&quot;s&quot;&gt;host.hostname = &quot;{{ item }}.domain.local&quot;;&lt;/span&gt;
          &lt;span class=&quot;s&quot;&gt;path = &quot;/usr/local/jails/{{ item }}&quot;;&lt;/span&gt;
          &lt;span class=&quot;s&quot;&gt;exec.consolelog = &quot;/var/log/jail_{{ item }}.log&quot;;&lt;/span&gt;
          &lt;span class=&quot;s&quot;&gt;ip4.addr = {{ alias_ip }};&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;jails&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;flatten(levels=1)&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;loop_control&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;extended&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;yes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Let’s tell &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;rc.conf&lt;/code&gt; to run jails at startup.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;start jails at startup&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;community.general.sysrc&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;jail_enable&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;YES&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Finally, add the tasks to start the jails now. We can’t use &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;service&lt;/code&gt; module here, because &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;args&lt;/code&gt; argument don’t pass its value to &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;service jail &lt;span class=&quot;nv&quot;&gt;$action&lt;/span&gt;&lt;/code&gt;. The &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;service&lt;/code&gt; has a rc of &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;0&lt;/code&gt; if the service is already running, so it’s not a problem to trigger the start at each playbook run.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;start jails&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;shell&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;service jail start &quot;{{ item }}&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;loop&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;jails&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;flatten(levels=1)&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;}}&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;run-and-test&quot;&gt;Run and test&lt;/h4&gt;

&lt;p&gt;Run the playbook to provision jails.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible-playbook playbook.yml
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;...]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : create zfs jails dataset] &lt;span class=&quot;k&quot;&gt;****************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : create zfs per jail dataset] &lt;span class=&quot;k&quot;&gt;*************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : template bsdinstall script] &lt;span class=&quot;k&quot;&gt;**************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : bsdinstall jails] &lt;span class=&quot;k&quot;&gt;************************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : authorize your ssh key] &lt;span class=&quot;k&quot;&gt;********************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : permit root login] &lt;span class=&quot;k&quot;&gt;*************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : &lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;default jails config] &lt;span class=&quot;k&quot;&gt;****************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : &lt;span class=&quot;nb&quot;&gt;declare &lt;/span&gt;jails] &lt;span class=&quot;k&quot;&gt;***************************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : start jails at startup] &lt;span class=&quot;k&quot;&gt;******************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test]

TASK &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;jails : start jails] &lt;span class=&quot;k&quot;&gt;*****************************************************************************************&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
changed: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;host-test] &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;nginx&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

PLAY RECAP &lt;span class=&quot;k&quot;&gt;*********************************************************************************************************&lt;/span&gt;
host-test                  : &lt;span class=&quot;nv&quot;&gt;ok&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;4    &lt;span class=&quot;nv&quot;&gt;changed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;10    &lt;span class=&quot;nv&quot;&gt;unreachable&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;failed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;skipped&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;rescued&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0    &lt;span class=&quot;nv&quot;&gt;ignored&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;List your running jails and check their IP.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; shell &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;jls&quot;&lt;/span&gt;
host-test | CHANGED | &lt;span class=&quot;nv&quot;&gt;rc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0 &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;
   JID  IP Address      Hostname                      Path
     1  192.168.0.101   bind.domain.local             /usr/local/jails/bind
     2  192.168.0.102   nginx.domain.local            /usr/local/jails/nginx

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; shell &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;jexec bind ifconfig | grep inet&quot;&lt;/span&gt;
host-test | CHANGED | &lt;span class=&quot;nv&quot;&gt;rc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0 &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;
	inet 192.168.0.101 netmask 0xffffff00 broadcast 192.168.0.255

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible host-test &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; shell &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;jexec nginx ifconfig | grep inet&quot;&lt;/span&gt;
host-test | CHANGED | &lt;span class=&quot;nv&quot;&gt;rc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0 &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;
	inet 192.168.0.102 netmask 0xffffff00 broadcast 192.168.0.255
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can now reach your jails with Ansible, just add their entries in your inventory.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;EOF&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt; &amp;gt;&amp;gt; hosts
bind ansible_host=192.168.0.101
nginx ansible_host=192.168.0.102
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF

&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ansible nginx:bind &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; ping
&lt;span class=&quot;nb&quot;&gt;bind&lt;/span&gt; | SUCCESS &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;&quot;ansible_facts&quot;&lt;/span&gt;: &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;s2&quot;&gt;&quot;discovered_interpreter_python&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;/usr/local/bin/python3.7&quot;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;,
    &lt;span class=&quot;s2&quot;&gt;&quot;changed&quot;&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;,
    &lt;span class=&quot;s2&quot;&gt;&quot;ping&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;pong&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
nginx | SUCCESS &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;s2&quot;&gt;&quot;ansible_facts&quot;&lt;/span&gt;: &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;s2&quot;&gt;&quot;discovered_interpreter_python&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;/usr/local/bin/python3.7&quot;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;,
    &lt;span class=&quot;s2&quot;&gt;&quot;changed&quot;&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;,
    &lt;span class=&quot;s2&quot;&gt;&quot;ping&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;pong&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the &lt;a href=&quot;/2021/06/09/jails-part-2.html&quot;&gt;next part&lt;/a&gt;, we will see how to provision &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;vnet&lt;/code&gt; jails.&lt;/p&gt;</content><author><name></name></author><summary type="html"></summary></entry><entry><title type="html">Git pre commit hooks</title><link href="/2021/06/02/git-pre-commit.html" rel="alternate" type="text/html" title="Git pre commit hooks" /><published>2021-06-02T00:00:00+02:00</published><updated>2021-06-02T00:00:00+02:00</updated><id>/2021/06/02/git-pre-commit</id><content type="html" xml:base="/2021/06/02/git-pre-commit.html">&lt;p&gt;&lt;a href=&quot;https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks&quot;&gt;Git Hooks&lt;/a&gt; are shell scripts integrated to your git directory. They are triggered before: &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;pre-&lt;/code&gt; or after: &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;post-&lt;/code&gt; some actions, &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;commit&lt;/code&gt;, &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;push&lt;/code&gt;, &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;checkout&lt;/code&gt; and run locally. The most useful function is &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;pre-commit&lt;/code&gt; which can check your code syntax, lint to improve the code quality, or trigger any local test.&lt;/p&gt;

&lt;p&gt;Hooks are mostly always the same, users share them on github and &lt;a href=&quot;https://pre-commit.com/hooks.html&quot;&gt;pre-commit&lt;/a&gt; tool automates hooks deployment.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;pre-commit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;deploy-a-hook&quot;&gt;Deploy a hook&lt;/h3&gt;

&lt;p&gt;Create a test directory and git it.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;mkdir &lt;/span&gt;git-commit-test &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;git-commit-test

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git init
Initialized empty Git repository &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; /home/user/dev/git-commit-test/.git/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Choose hooks projects you want to use in &lt;a href=&quot;https://pre-commit.com/hooks.html&quot;&gt;pre-commit hooks list&lt;/a&gt;.&lt;br /&gt;
For this exemple, we will use yaml and shell checkers.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;&quot;&gt;https://github.com/pre-commit/pre-commit-hooks&lt;/a&gt; : check-yaml and trailing-whitespace&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;&quot;&gt;https://github.com/shellcheck-py/shellcheck-py&lt;/a&gt; : shellcheck&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pre-commit configuration file is &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;.pre-commit-config.yaml&lt;/code&gt;, create it at the project root.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;repos&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;repo&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;https://github.com/pre-commit/pre-commit-hooks&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;rev&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;v4.0.1&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;hooks&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;check-yaml&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;trailing-whitespace&lt;/span&gt;
&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;repo&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;https://github.com/shellcheck-py/shellcheck-py&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;rev&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;v0.7.2.1&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;hooks&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;shellcheck&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To init hook deployment, use &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt;&lt;/code&gt; subcommand.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pre-commit &lt;span class=&quot;nb&quot;&gt;install
&lt;/span&gt;pre-commit installed at .git/hooks/pre-commit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;test-it&quot;&gt;Test it&lt;/h3&gt;

&lt;p&gt;Let’s add a shell script to the project and a yaml file with some errors.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;EOF&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt; &amp;gt; test.sh
#!/bin/bash
var=1
echo &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$var&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF

&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;EOF&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt; &amp;gt; test.yml
- key1
  key2:
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Add those files to the index, &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;pre-commit&lt;/code&gt; defaulty ignore files outside the index.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git add &lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt;

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git status
On branch main

No commits yet

Changes to be committed:
  &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;use &lt;span class=&quot;s2&quot;&gt;&quot;git rm --cached &amp;lt;file&amp;gt;...&quot;&lt;/span&gt; to unstage&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
	new file:   .pre-commit-config.yaml
	new file:   test.sh
	new file:   test.yml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And just commit to fire your hooks !&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git commit &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;added a great shell script and his yaml file&quot;&lt;/span&gt;
Check Yaml...............................................................Failed
- hook &lt;span class=&quot;nb&quot;&gt;id&lt;/span&gt;: check-yaml
- &lt;span class=&quot;nb&quot;&gt;exit &lt;/span&gt;code: 1

mapping values are not allowed &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;this context
  &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;test.yml&quot;&lt;/span&gt;, line 2, column 6

Trim Trailing Whitespace.................................................Failed
- hook &lt;span class=&quot;nb&quot;&gt;id&lt;/span&gt;: trailing-whitespace
- &lt;span class=&quot;nb&quot;&gt;exit &lt;/span&gt;code: 1
- files were modified by this hook

Fixing test.sh

shellcheck...............................................................Failed
- hook &lt;span class=&quot;nb&quot;&gt;id&lt;/span&gt;: shellcheck
- &lt;span class=&quot;nb&quot;&gt;exit &lt;/span&gt;code: 1

In test.sh line 2:
&lt;span class=&quot;nv&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1
^-^ SC2034: var appears unused. Verify use &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;or &lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;used externally&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt;

For more information:
  https://www.shellcheck.net/wiki/SC2034 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt; var appears unused. Verify use &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;o...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As pre-commit hooks failed, the commit was not created.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git log
fatal: your current branch &lt;span class=&quot;s1&quot;&gt;&apos;main&apos;&lt;/span&gt; does not have any commits yet
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Trailing whitespace hooks automatically fixed his errors.&lt;br /&gt;
If you fix your shell script and yaml file, your commit will be ok.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sed&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-i&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;s/$var/\&quot;$var\&quot;/&apos;&lt;/span&gt; test.sh

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sed&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-i&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;s/key1/key1:/&apos;&lt;/span&gt; test.yml

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git add test.&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git commit &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;first sane commit&quot;&lt;/span&gt;
Check Yaml...............................................................Passed
Trim Trailing Whitespace.................................................Passed
shellcheck...............................................................Passed
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;main &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;root-commit&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; c689536] first sane commit
 3 files changed, 15 insertions&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;+&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
 create mode 100644 .pre-commit-config.yaml
 create mode 100644 test.sh
 create mode 100644 test.yml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;custom-ansible-hook&quot;&gt;Custom Ansible Hook&lt;/h3&gt;

&lt;p&gt;I wanted to be able to check ansible syntax before.&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;repo&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;local&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;hooks&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ansible-syntax-check&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Ansible syntax check&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;ansible-playbook&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;--syntax-check&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;playbook.yml&quot;&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;pass_filenames&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;no&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;types_or&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;yaml&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;jinja&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;]&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;system&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Create the playbook.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;EOF&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt; &amp;gt; playbook.yml
- hosts: test
  tasks:
    - name: copy test.sh
      copyy:
        src: ./test.sh
        dest: dir
&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;EOF
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Then try to commit it.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git add &lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git commit &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;added an insane playbook&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;user@osz git-commit-test]&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git commit &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;added an insane playbook&quot;&lt;/span&gt;
Check Yaml...............................................................Passed
Trim Trailing Whitespace.................................................Passed
shellcheck...........................................&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;no files to check&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;Skipped
Ansible syntax check.....................................................Failed
- hook &lt;span class=&quot;nb&quot;&gt;id&lt;/span&gt;: ansible-syntax-check
- &lt;span class=&quot;nb&quot;&gt;exit &lt;/span&gt;code: 4

&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;WARNING]: No inventory was parsed, only implicit localhost is available
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match &lt;span class=&quot;s1&quot;&gt;&apos;all&apos;&lt;/span&gt;
ERROR! couldn&lt;span class=&quot;s1&quot;&gt;&apos;t resolve module/action &apos;&lt;/span&gt;copyy&lt;span class=&quot;s1&quot;&gt;&apos;. This often indicates a misspelling, missing collection, or incorrect module path.

The error appears to be in &apos;&lt;/span&gt;/home/user/dev/git-commit-test/playbook.yml&lt;span class=&quot;s1&quot;&gt;&apos;: line 3, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  tasks:
    - name: copy test.sh
      ^ here
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As no shell script was in the index, &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;shellcheck&lt;/code&gt; was skipped, but pre-commit detected our mispelled &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;copy&lt;/code&gt; ansible module.&lt;/p&gt;</content><author><name></name></author><summary type="html">Git Hooks are shell scripts integrated to your git directory. They are triggered before: pre- or after: post- some actions, commit, push, checkout and run locally. The most useful function is pre-commit which can check your code syntax, lint to improve the code quality, or trigger any local test.</summary></entry><entry><title type="html">Nas project - part 3</title><link href="/2021/05/30/nas-part-3.html" rel="alternate" type="text/html" title="Nas project - part 3" /><published>2021-05-30T00:00:00+02:00</published><updated>2021-05-30T00:00:00+02:00</updated><id>/2021/05/30/nas-part-3</id><content type="html" xml:base="/2021/05/30/nas-part-3.html">&lt;p&gt;In &lt;a href=&quot;/2021/05/21/nas-part-2.html&quot;&gt;part 2&lt;/a&gt;, I setup my nas, but I didn’t notice that I created ZFS pool without mirroring.&lt;/p&gt;

&lt;p&gt;Let’s try to fix this.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;zpool remove dpool sdc
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;zpool status
  pool: dpool
 state: ONLINE
 remove: Evacuation of /dev/sdc1 &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;progress since Sun May 30 08:51:38 2021
 4.23G copied out of 202G at 80.1M/s, 2.10% &lt;span class=&quot;k&quot;&gt;done&lt;/span&gt;, 0h42m to go
    566K memory used &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;removed device mappings
config:

        NAME          STATE     READ WRITE CKSUM
        dpool         ONLINE       0     0     0
          sdb         ONLINE       0     0     0
          sdc         ONLINE       0     0     0

errors: No known data errors
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;After it completes, I attach now the newly free disk to mirror the first one.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;zpool attach dpool sdb sdc
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;zpool status
  pool: dpool
 state: ONLINE
status: One or more devices is currently being resilvered.  The pool will
        &lt;span class=&quot;k&quot;&gt;continue &lt;/span&gt;to &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt;, possibly &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;a degraded state.
action: Wait &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;the resilver to complete.
  scan: resilver &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;progress since Sun May 30 09:38:12 2021
        404G scanned at 2.43G/s, 1.52G issued at 9.41M/s, 404G total
        1.53G resilvered, 0.38% &lt;span class=&quot;k&quot;&gt;done&lt;/span&gt;, no estimated completion &lt;span class=&quot;nb&quot;&gt;time
&lt;/span&gt;remove: Removal of vdev 1 copied 202G &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;0h44m, completed on Sun May 30 09:36:27 2021
    566K memory used &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;removed device mappings
config:

        NAME          STATE     READ WRITE CKSUM
        dpool         ONLINE       0     0     0
          mirror-0    ONLINE       0     0     0
            sdb       ONLINE       0     0     0
            sdc       ONLINE       0     0     0  &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;resilvering&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

errors: No known data errors
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It ended without any stress/warning/error… how much do &lt;strong&gt;I love ZFS&lt;/strong&gt; !&lt;/p&gt;

&lt;h3 id=&quot;dns-day&quot;&gt;DNS day&lt;/h3&gt;

&lt;p&gt;I want to configure a authoritative DNS for my &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;eoli3n.eu.org&lt;/code&gt; domain.&lt;br /&gt;
This DNS server will not be used as a recursive one, even locally, I just want it to resolv &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;.eoli3n.eu.org&lt;/code&gt;.&lt;br /&gt;
Following &lt;a href=&quot;https://wiki.debian.org/Bind9#Debian_Jessie_and_later&quot;&gt;bind9 debian wiki page&lt;/a&gt;, I setup a bind authoritative server in a chroot. Here’s the bind config&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; /etc/bind/named.conf.options
options &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    directory &lt;span class=&quot;s2&quot;&gt;&quot;/var/cache/bind&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    // Listen on ipv4 interfaces only
    listen-on &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        127.0.0.1&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        192.168.0.253&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    listen-on-v6      &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; none&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    // Hide version
    version &lt;span class=&quot;s2&quot;&gt;&quot;[SECURED]&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    // disable zone transfert
    allow-transfer    &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;none&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    // disable recursion
    recursion no&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    // allow query
    allow-query       &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; any&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    allow-query-cache &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; any&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; /etc/bind/named.conf.local
// https://serverfault.com/a/306109/339917
include &lt;span class=&quot;s2&quot;&gt;&quot;/etc/bind/zones.rfc1918&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

zone &lt;span class=&quot;s2&quot;&gt;&quot;eoli3n.eu.org.&quot;&lt;/span&gt; IN &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;type &lt;/span&gt;master&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    file &lt;span class=&quot;s2&quot;&gt;&quot;selfhost.zone&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; /var/bind9/chroot/var/cache/bind/selfhost.zone
&lt;span class=&quot;nv&quot;&gt;$TTL&lt;/span&gt; 86400
@       IN      SOA     ns1 root &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
                        1622390729 &lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; serial number
                        8h &lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; Refresh
                        2h &lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; Retry
                        8h &lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; Expire
                        4m &lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; Min TTL
                        &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

@       IN      NS      ns1
ns1     IN      A       &lt;span class=&quot;nv&quot;&gt;$public_ip&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;       IN      A       &lt;span class=&quot;nv&quot;&gt;$public_ip&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Lets test it&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;dig @127.0.0.1 ns1.eoli3n.eu.org
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;...]
&lt;span class=&quot;p&quot;&gt;;;&lt;/span&gt; ANSWER SECTION:
ns1.eoli3n.eu.org.	86400	IN	A	&lt;span class=&quot;nv&quot;&gt;$public_ip&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;;;&lt;/span&gt; AUTHORITY SECTION:
eoli3n.eu.org.		86400	IN	NS	ns1.eoli3n.eu.org.
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;...]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;get-my-own-domain-on-euorg&quot;&gt;Get my own domain on eu.org&lt;/h3&gt;

&lt;p&gt;I asked for &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;eoli3n.eu.org&lt;/code&gt; domain by creating a request on the free domain registrar &lt;strong&gt;eu.org&lt;/strong&gt;.&lt;br /&gt;
To configure it, just add &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;ns1.eoli3n.eu.org&lt;/code&gt; glue record with your public IP and redirect TCP/UDP on port 53 to your DNS server on your ISP router.&lt;/p&gt;</content><author><name></name></author><summary type="html">In part 2, I setup my nas, but I didn’t notice that I created ZFS pool without mirroring.</summary></entry><entry><title type="html">Password store</title><link href="/2021/05/30/passwords.html" rel="alternate" type="text/html" title="Password store" /><published>2021-05-30T00:00:00+02:00</published><updated>2021-05-30T00:00:00+02:00</updated><id>/2021/05/30/passwords</id><content type="html" xml:base="/2021/05/30/passwords.html">&lt;p&gt;Password managment is the cornerstone of services security. If you use web, you would create one random password per service, and activate &lt;a href=&quot;https://en.wikipedia.org/wiki/Time-based_One-Time_Password&quot;&gt;Time-based One-Time Password&lt;/a&gt; for all important one, like mail.&lt;/p&gt;

&lt;p&gt;I used firefox lockwise to manage my web passwords, and FreeOTP on Android.&lt;br /&gt;
Firefox Lockwise can be configured to asks for a master password at every accesses.&lt;br /&gt;
Easy synchronization between multiple hosts, including my phone, sticked me to it.&lt;/p&gt;

&lt;p&gt;Problem is that I don’t really own my data, that I can’t drop Firefox if I would like to, and I can’t manage non web passwords.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.passwordstore.org/&quot;&gt;Pass&lt;/a&gt; defines itself like “&lt;strong&gt;the standard unix password manager&lt;/strong&gt;”.&lt;br /&gt;
It uses &lt;a href=&quot;https://gnupg.org/&quot;&gt;gnupg&lt;/a&gt; to encrypt passwords as &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;.gpg&lt;/code&gt; files, and git to distribute.&lt;br /&gt;
A clever extension lets you use it with &lt;a href=&quot;https://github.com/davatorium/rofi&quot;&gt;rofi&lt;/a&gt; : &lt;a href=&quot;https://github.com/carnager/rofi-pass&quot;&gt;rofi-pass&lt;/a&gt;&lt;br /&gt;
But &lt;em&gt;pass&lt;/em&gt; defaulty miss some comfortable features:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Automatic commit/push/pull, if you forget to commit a change, you can’t access it on other devices&lt;/li&gt;
  &lt;li&gt;TOTP generator, but &lt;a href=&quot;https://github.com/tadfisher/pass-otp&quot;&gt;pass-otp&lt;/a&gt; exists&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href=&quot;https://www.gopass.pw/&quot;&gt;Gopass&lt;/a&gt; handles those by default, and even more.&lt;br /&gt;
You can manage multiple password stores and share them with your teams, with access control lists based on gpg.&lt;br /&gt;
A password leak and quality checker is embeeded, desktop notifications, etc..&lt;/p&gt;

&lt;h3 id=&quot;setup-and-configure-gnupg&quot;&gt;Setup and configure GnuPG&lt;/h3&gt;

&lt;p&gt;First, you need to create a gpg keypair. Ensure that you use gnupg2, some linux distros has gnupg &lt;em&gt;v1.x&lt;/em&gt; in a different package.&lt;/p&gt;

&lt;p&gt;On Voidlinux:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gpg2 &lt;span class=&quot;nt&quot;&gt;--full-generate-key&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# (1) RSA et RSA&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# size: 3073 bits&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# set expiration&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# set your real name, email and comment&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Generate a revoke certificate and store it in a safe place, check your &lt;em&gt;keyid&lt;/em&gt; with &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;gpg2 &lt;span class=&quot;nt&quot;&gt;--list-keys&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gpg2 &lt;span class=&quot;nt&quot;&gt;--gen-revoke&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--output&lt;/span&gt; revoke.asc &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$key_id&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;To backup your key, export you secret key and the trust db&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gpg2 &lt;span class=&quot;nt&quot;&gt;--export-secret-keys&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--armor&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$key_id&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; secret.asc
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gpg2 &lt;span class=&quot;nt&quot;&gt;--export-ownertrust&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; trustdb-backup.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Gnupg defaulty use a ncurses pinentry, you would change it for a graphical one, I chose &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;pinentry-gtk&lt;/code&gt; and configured gpg by creating the file &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;~/.gnupg/gpg-agent.conf&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pinentry-program /bin/pinentry-gtk-2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To test gpupg, you can try to sign a file with &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;gpg2 &lt;span class=&quot;nt&quot;&gt;--sign&lt;/span&gt; test.file&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I use &lt;a href=&quot;https://www.funtoo.org/Keychain&quot;&gt;keychain&lt;/a&gt; to autostart gpg agent at first shell login, with fish&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; ~/.config/fish/conf.d/keychain.fish
&lt;span class=&quot;c&quot;&gt;# https://stackoverflow.com/questions/39494631/gpg-failed-to-sign-the-data-fatal-failed-to-write-commit-object-git-2-10-0&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-x&lt;/span&gt; GPG_TTY &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;tty&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# https://github.com/fish-shell/fish-shell/issues/4583&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;status &lt;span class=&quot;nt&quot;&gt;--is-interactive&lt;/span&gt;
    keychain &lt;span class=&quot;nt&quot;&gt;--eval&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--agents&lt;/span&gt; ssh &lt;span class=&quot;nt&quot;&gt;--quiet&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-Q&lt;/span&gt; id_rsa | &lt;span class=&quot;nb&quot;&gt;source
    &lt;/span&gt;keychain &lt;span class=&quot;nt&quot;&gt;--eval&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--agents&lt;/span&gt; gpg &lt;span class=&quot;nt&quot;&gt;--quiet&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--gpg2&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-Q&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;source
&lt;/span&gt;end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I don’t target the key to load, when I will use it, it will be added after typing my passphrase.&lt;br /&gt;
Gpg agent is not like SSH agent, it forgets the passphrase token after &lt;em&gt;600 seconds&lt;/em&gt; by default.&lt;/p&gt;

&lt;h3 id=&quot;configure-git-with-gnupg&quot;&gt;Configure Git with Gnupg&lt;/h3&gt;

&lt;p&gt;Now, you need a centralised git repository, and the ability to sign your commits.&lt;br /&gt;
I created mine on my nas server with &lt;a href=&quot;https://gitolite.com/gitolite/index.html&quot;&gt;gitolite&lt;/a&gt;, but you can use a Github private repository.&lt;br /&gt;
To make signing work, I needed to edit my git-config to match my gpg binary and my gpg key.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; ~/.gitconfig
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;user]
    name &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; eoli3n
    email &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; jonathan.kirszling@runbox.com
    signingkey &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; eoli3n
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;pull]
    rebase &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;gpg]
    program &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; gpg2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Let’s try to sign a commit:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;mkdir &lt;/span&gt;git-gpg-test
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;git-gpg-test/
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;testing&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; README.md
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git init
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git add README.md
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git commit &lt;span class=&quot;nt&quot;&gt;-S&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;testing to sign this commit&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;master &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;commit racine&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; c8fb990] testing to sign this commit
 1 file changed, 1 insertion&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;+&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
 create mode 100644 README.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, great, now let’s create the password store.&lt;/p&gt;

&lt;h3 id=&quot;password-store&quot;&gt;Password Store&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gopass setup
   __     _    _ _      _ _   ___   ___
 /&lt;span class=&quot;s1&quot;&gt;&apos;_ &apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;/&lt;span class=&quot;s1&quot;&gt;&apos;_&apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;_&apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt; /&lt;span class=&quot;s1&quot;&gt;&apos;_&apos;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;/&lt;span class=&quot;s1&quot;&gt;&apos;,__)/&apos;&lt;/span&gt;,__&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;_&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; |&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;_&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;| &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;_&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;)(&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;_| |&lt;span class=&quot;se&quot;&gt;\_&lt;/span&gt;_, &lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;__, &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;s1&quot;&gt;&apos;\__  |&apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\_&lt;/span&gt;__/&lt;span class=&quot;s1&quot;&gt;&apos;| ,__/&apos;&apos;\__,_)(____/(____/
( )_) |       | |
 \___/&apos;&lt;/span&gt;       &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;_&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

🌟 Welcome to gopass!
🌟 Initializing a new password store ...
🌟 Configuring your password store ...
🎮 Please &lt;span class=&quot;k&quot;&gt;select &lt;/span&gt;a private key &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;encrypting secrets:
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;0] gpg - 0xFEEDBEEF - Jonathan Kirszling &amp;lt;jonathan.kirszling@runbox.com&amp;gt;
Please enter the number of a key &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;0-12, &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;q]uit&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;q to abort&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;0]: 0
❓ Do you want to add a git remote? &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;y/N/q]: y
Configuring the git remote ...
Please enter the git remote &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;your shared store &lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt;: git@nas.domain.fr:passwords.git
✅ Configured
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;add-your-first-password&quot;&gt;Add your first password&lt;/h3&gt;

&lt;p&gt;Use &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;insert&lt;/code&gt; subcommand to create password entries&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gopass insert work/test
Enter password &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;work/test:
Retype password &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;work/test:
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Querying it will prompt for you gpg passphrase.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gopass work/test
Secret: work/test

Passw0rd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;add-a-totp&quot;&gt;Add a TOTP&lt;/h3&gt;

&lt;p&gt;To add a TOTP key, you need to use &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;span class=&quot;nt&quot;&gt;--multiline&lt;/span&gt;&lt;/code&gt; argument&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gopass insert &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; work/vpn
totp: XXXXXXXXXXXXXXXXXXXXXX

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gopass totp work/vpn
069268 lasts 8s 	|----------------------&lt;span class=&quot;o&quot;&gt;========&lt;/span&gt;|
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;synchronization-with-android&quot;&gt;Synchronization with Android&lt;/h3&gt;

&lt;p&gt;On Android, you need &lt;a href=&quot;https://www.openkeychain.org/&quot;&gt;OpenKeychain&lt;/a&gt;, to add your previously exported gpg secret key.&lt;br /&gt;
To be able to use &lt;em&gt;TOTP&lt;/em&gt; and your password store, use &lt;a href=&quot;https://github.com/android-password-store/Android-Password-Store&quot;&gt;Password Store&lt;/a&gt; with your ssh key to reach you git &lt;em&gt;passwords&lt;/em&gt; repository. No need to use &lt;em&gt;FreeOTP&lt;/em&gt; anymore.&lt;br /&gt;
&lt;em&gt;Password Store&lt;/em&gt; does not pull/push commit automatically, don’t forget to sync from the app !&lt;/p&gt;

&lt;h3 id=&quot;configure-a-new-node&quot;&gt;Configure a new node&lt;/h3&gt;

&lt;p&gt;Import your gpg key and your trust db&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gpg2 —-import secret.asc
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;rm&lt;/span&gt; ~/.gnupg/trustdb.gpg
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gpg2 &lt;span class=&quot;nt&quot;&gt;--import-ownertrust&lt;/span&gt; &amp;lt; trustdb-backup.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then gopass wrap your &lt;em&gt;passwords&lt;/em&gt; reporistory git clone&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gopass clone git@nas.domain.fr:passwords.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;You project with be stored in &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;.local/share/gopass/stores/root/&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;go-a-bit-further&quot;&gt;Go a bit further&lt;/h3&gt;

&lt;p&gt;On my desktop hosts, I now need to find an alternative to &lt;em&gt;rofi-pass&lt;/em&gt; for &lt;a href=&quot;https://cloudninja.pw/docs/wofi.html&quot;&gt;Wofi&lt;/a&gt;.&lt;br /&gt;
&lt;em&gt;gopass&lt;/em&gt; should be fully compatible with &lt;em&gt;pass&lt;/em&gt; by default, except for totp generator which differs a bit.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;gopass&lt;/em&gt; has a great plugin to manage passwords from browser: &lt;a href=&quot;https://github.com/gopasspw/gopassbridge&quot;&gt;gopassbridge&lt;/a&gt;.&lt;br /&gt;
It would be a great firefox lockwise replacement.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;20/06/23 edit&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/eoli3n/dotfiles/blob/5187359320e5870dbfac50bcf1d9b678ecd605e9/roles/sway/templates/config.j2#L34-L35&quot;&gt;This&lt;/a&gt; is the way to get &lt;em&gt;wofi-pass&lt;/em&gt; working, with autocopy and totp mode.&lt;/p&gt;</content><author><name></name></author><summary type="html">Password managment is the cornerstone of services security. If you use web, you would create one random password per service, and activate Time-based One-Time Password for all important one, like mail.</summary></entry><entry><title type="html">Improve Backups</title><link href="/2021/05/21/improve-backups.html" rel="alternate" type="text/html" title="Improve Backups" /><published>2021-05-21T00:00:00+02:00</published><updated>2021-05-21T00:00:00+02:00</updated><id>/2021/05/21/improve-backups</id><content type="html" xml:base="/2021/05/21/improve-backups.html">&lt;p&gt;After &lt;a href=&quot;/2020/04/30/backup.html&quot;&gt;my first post&lt;/a&gt; about how to setup BorgBackup and a first install of a home nas, I do have now two borg servers, lets spread our backups !&lt;/p&gt;

&lt;h3 id=&quot;drop-the-shell-backup-script&quot;&gt;Drop the shell backup script&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://torsion.org/borgmatic/&quot;&gt;Borgmatic&lt;/a&gt; is an overlay to BorgBackup which let you configure everything with a yaml file and wrap Borg command to let you interact with your repository easierly.&lt;/p&gt;

&lt;p&gt;Here a &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;/etc/borgmatic/config.yaml&lt;/code&gt; file exemple&lt;/p&gt;

&lt;p&gt;&lt;em&gt;11/06/23 edit: use &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;patterns&lt;/code&gt; instead of &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;exclude_patterns&lt;/code&gt; to be able to backup directories in a declarative way&lt;/em&gt;&lt;br /&gt;
See &lt;a href=&quot;https://github.com/borgbackup/borg/pull/7644&quot;&gt;borg patterns help&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;source_directories&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/&lt;/span&gt;

  &lt;span class=&quot;na&quot;&gt;repositories&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;root@nas:/data/backups/osz&lt;/span&gt;

  &lt;span class=&quot;na&quot;&gt;exclude_caches&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;true&lt;/span&gt;

  &lt;span class=&quot;na&quot;&gt;patterns&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;R /&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;**/lost+found&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;**/*.iso&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;**/*.mkv&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;**/*.vmdk&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;**/*.pyc&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;root/.cache&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;home/*/.cache&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;home/*/.var/app/*/cache&apos;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# flatpak caches&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;home/*/.local/share/Steam&apos;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# steam installed games&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;home/*/.local/share/Trash&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;etc/**&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;root/**&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;home/**&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;var/log/**&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;re:^(dev|proc|run|sys|tmp)&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;**&apos;&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;storage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;encryption_passphrase&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;***************************&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;compression&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;zstd&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;archive_name_format&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{hostname}-{now:%Y-%m-%dT%H:%M:%S}&apos;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;ssh_command&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh -i /root/.ssh/backup_rsa&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;relocated_repo_access_is_ok&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;true&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;retention&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{hostname}-&apos;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;keep_daily&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;7&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;keep_weekly&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;4&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;keep_monthly&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;6&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;keep_yearly&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;consistency&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;check_last&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On the repository server, you need to add a restricted authorized_key as explained in my previous post.&lt;br /&gt;
Then you can create the repository and start your first backup.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;borgmatic init &lt;span class=&quot;nt&quot;&gt;--encryption&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;repokey-blake2
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;borgmatic &lt;span class=&quot;nt&quot;&gt;-v2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As the process is now standard, you can write an ansible task to add an anacron and automate backups more nicely.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;automate daily backups&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;copy&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/etc/cron.daily/backup&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0755&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;|&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;#!/bin/bash&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;borgmatic -v1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The borgmatic toolbox let you interact with the repository from the client.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;borgmatic info
root@nas:/data/backups/osz: Displaying summary info &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;archives
Repository ID: 664b076398e3d4ef96031d33f99ec0df1bb98a8ca39b181052f5dbc6c335f70e
Location: ssh://root@nas/data/backups/osz
Encrypted: Yes &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;repokey BLAKE2b&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
Cache: /root/.cache/borg/664b076398e3d4ef96031d33f99ec0df1bb98a8ca39b181052f5dbc6c335f70e
Security &lt;span class=&quot;nb&quot;&gt;dir&lt;/span&gt;: /root/.config/borg/security/664b076398e3d4ef96031d33f99ec0df1bb98a8ca39b181052f5dbc6c335f70e
&lt;span class=&quot;nt&quot;&gt;------------------------------------------------------------------------------&lt;/span&gt;
                       Original size      Compressed size    Deduplicated size
All archives:                1.90 TB              1.08 TB            149.50 GB
                       Unique chunks         Total chunks
Chunk index:                  961954              8286300

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;borgmatic list
root@nas:/data/backups/osz: Listing archives
osz-2021-05-14T18:19:19-voidlinux-install Fri, 2021-05-14 18:19:20 &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;dd21865bff728fdf4751cdc0e1f714164436eb5863452298b72952093dfbad4c]
osz-2021-05-15T11:50:05              Sat, 2021-05-15 11:50:06 &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;a38b92d57f58c97195e42047611679aa24a065a092da93d6ed9a68d7d94a52ad]
osz-2021-05-16T12:21:03              Sun, 2021-05-16 12:21:03 &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;b2e2f061939bb4818cb7be33e7da2c572ce7b60ebb6f9482ed317e18cf01895f]
osz-2021-05-17T09:23:14              Mon, 2021-05-17 09:23:15 &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;183c1b2f399999012cfa977a3b5f67ca3b8b0299384adfad486e3858a469659e]
osz-2021-05-18T18:36:34              Tue, 2021-05-18 18:36:35 &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;b71d73f6d62a328ff09c5728ddb042b6858148fcfbfe078828178abd34a10795]
osz-2021-05-19T08:16:24              Wed, 2021-05-19 08:16:24 &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;514b13dcdfbca936930adf67066bb7fcb5e668f5301c0d5ec1a98915c9926bb9]
osz-2021-05-20T09:40:59              Thu, 2021-05-20 09:40:59 &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;de40b1ca2cfe99893cb8023b2c496ba56695f3596199a126ac79ccf36ee566d0]

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;borgmatic mount &lt;span class=&quot;nt&quot;&gt;--archive&lt;/span&gt; osz-2021-05-19T08:16:24 &lt;span class=&quot;nt&quot;&gt;--mount-point&lt;/span&gt; /mnt

&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo ls&lt;/span&gt; /mnt
bin   dev  etc	lib	lib64  mnt  proc  run	sys	tmp  var
boot  efi  home  lib32	media  opt  root  sbin	sysroot  usr
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;spread-your-backups&quot;&gt;Spread your Backups&lt;/h3&gt;

&lt;p&gt;I use &lt;a href=&quot;https://syncthing.net/&quot;&gt;Syncthing&lt;/a&gt; to sync my backups over the network between two repository servers.&lt;br /&gt;
The important line in the client configuration is &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;relocated_repo_access_is_ok: &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;/code&gt; which lets you access your backups from the second server.&lt;br /&gt;
Syncing a borg repository is not the recommended way to spread your backups, because if a data corruption occurs on one side, it is stupidly replicated.&lt;br /&gt;
You should prefer to add a second repository in the yaml config, borgmatic will trigger two separated backups.&lt;/p&gt;

&lt;p&gt;I chose to sync with Syncthing because one of my repository is accessible only from a OTP secured vpn. I can’t automate VPN connection on all clients that I backup.&lt;/p&gt;

&lt;p&gt;The replication is done in two ways, from &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;server 1&lt;/code&gt; to &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;server 2&lt;/code&gt; and vice-versa.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;02/01/22 edit&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As borg &lt;a href=&quot;https://borgbackup.readthedocs.io/en/stable/faq.html#can-i-copy-or-synchronize-my-repo-to-another-location&quot;&gt;documentation says&lt;/a&gt;, borg repositories are not designed to be synced.&lt;br /&gt;
When I switched to redundant backups, I had to debug my repositories for few hours… So, just ,don’t.&lt;br /&gt;
Using two backup locations in borgmatic config will took twice the time, but security worth it.&lt;/p&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;na&quot;&gt;repositories&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;root@nas:/data/backups/osz&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;root@borgbase:/repo&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;online-backups&quot;&gt;Online Backups&lt;/h3&gt;

&lt;p&gt;If you backup at home and at a different location, that’s pretty solid. I was annoyed by the fact that I backup my personnal data at work as second place, and wanted, for my most important data, to be safe to move in another city, and changing work without to be worried about my backups.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.borgbase.com/&quot;&gt;BorgBase&lt;/a&gt; describes itself as “Simple and Secure Offsite Backups” service.&lt;br /&gt;
To use it, simply open an account for free, to test. Then you will be able to upgrade your plan to the 100G small plan. That’s enough for me, for my most important data, and only costs 2€/month under 100G, and then 0.01€/Go/month.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/server/borgbase.png&quot; alt=&quot;borgbase&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Repositories support encryption, and the web UI is secured with 2fa TOTP authentication.&lt;br /&gt;
I upload my backups at 12Mo/s, so I’m fully satisfied with the service.&lt;br /&gt;
You can enable alerts when repositories didn’t get any backup since some days.&lt;br /&gt;
Let’s see with time.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;11/06/23 edit&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;per-repository-configurations&quot;&gt;Per repository configurations&lt;/h3&gt;

&lt;p&gt;Borgbase storage is not free, you can then  define a shorter retention time on that repository.&lt;br /&gt;
To do this, we will use include feature of configuration files, which is documented in &lt;a href=&quot;https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#multiple-backup-configurations&quot;&gt;Borgmatic multiple backup configurations&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You need to create a &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;/etc/borgmatic/config-main.yaml&lt;/code&gt; file which will have configurations that apply to both repostiories. Then two &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;/etc/borgmatic.d/config-&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;nas,borgbase&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;.yaml&lt;/code&gt; for repository specific configurations, which will include the main configuration file. You need to put the main configuration file outside of &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;/etc/borgmatic.d&lt;/code&gt; or it will be processed as a third configuration file.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;borgmatic/config-main.yaml&lt;/code&gt; will contains in my case excludes and storage configurations.&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;exclude_caches&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;true&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;patterns&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;R /&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;**/lost+found&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;**/*.iso&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;**/*.mkv&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;**/*.vmdk&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;**/*.pyc&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;root/.cache&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;home/*/.cache&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;home/*/.var/app/*/cache&apos;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# flatpak caches&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;home/*/.local/share/Steam&apos;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# steam installed games&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;home/*/.local/share/Trash&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;etc/**&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;root/**&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;home/**&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;var/log/**&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;re:^(dev|proc|run|sys|tmp)&apos;&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;**&apos;&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;storage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;encryption_passphrase&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;********************************&quot;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;compression&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;zstd&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;archive_name_format&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{hostname}-{now:%Y-%m-%dT%H:%M:%S}&apos;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;relocated_repo_access_is_ok&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;borgmatic.d/config-nas.yaml&lt;/code&gt; and &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;borgmatic.d/config-nas.yaml&lt;/code&gt; will contain location with source path, the repository url, consistency and retention policies.&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;s&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;!include&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/root/.config/borgmatic/config-main.yaml&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;source_directories&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/&lt;/span&gt;

  &lt;span class=&quot;na&quot;&gt;repositories&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh://borg-base/./repo&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;borgbase&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;retention&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{hostname}-&apos;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;keep_daily&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;7&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;keep_weekly&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;4&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;consistency&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;check_last&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;s&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;!include&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/root/.config/borgmatic/config-main.yaml&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;source_directories&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/&lt;/span&gt;

  &lt;span class=&quot;na&quot;&gt;repositories&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssh://nas/backups/osz&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;nas&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;consistency&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;check_last&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;3&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;retention&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;{hostname}-&apos;&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;keep_daily&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;7&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;keep_weekly&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;4&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;keep_monthly&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;6&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;keep_yearly&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can now run &lt;code class=&quot;language-bash highlighter-rouge&quot;&gt;borgmatic&lt;/code&gt; and it will proceed as configured.&lt;br /&gt;
Note that &lt;a href=&quot;https://projects.torsion.org/borgmatic-collective/borgmatic/issues/635&quot;&gt;borgmatic now supports labels&lt;/a&gt; for repositories.&lt;/p&gt;</content><author><name></name></author><summary type="html">After my first post about how to setup BorgBackup and a first install of a home nas, I do have now two borg servers, lets spread our backups !</summary></entry></feed>