Skip to content

Manage a PiHole installation with Salt. Includes custom execution and state modules.

License

Notifications You must be signed in to change notification settings

lkubb/salt-pihole-formula

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PiHole Formula

Semantic Release pre-commit

Manage PiHole with Salt.

This formula also provides a custom execution and state module to manage PiHole beyond the setup.

Mind that automatic testing is currently not implemented, even if suggested otherwise from forking the official template formula.

See the full SaltStack Formulas installation and usage instructions.

If you are interested in writing or contributing to formulas, please pay attention to the Writing Formula Section.

If you want to use this formula, please pay attention to the FORMULA file and/or git tag, which contains the currently released version. This formula is versioned according to Semantic Versioning.

See Formula Versioning Section for more details.

If you need (non-default) configuration, please refer to:

An example pillar is provided, please see pillar.example. Note that you do not need to specify everything by pillar. Often, it's much easier and less resource-heavy to use the parameters/<grain>/<value>.yaml files for non-sensitive settings. The underlying logic is explained in map.jinja.

The following states are found in this formula:

Meta-state.

This installs the pihole package, manages the pihole configuration file, adlists, blacklists, custom CNAME and DNS config, groups, whitelists, then starts the pihole-FTL service. Also manages the lighttpd server regarding TLS configuration.

Installs PiHole only and syncs the custom modules found in this formula.

Warning:
This pipes the output fetching the installation script from the URL in pihole.lookup.setup_sh into a root shell because the setup is sadly rather the antithesis of straightforward to reproduce with Salt. It's possible to provide a local replacement for the script by overriding pihole.lookup.setup_sh e.g. to a salt:// URI.

Manages the PiHole, pihole-FTL and custom dnsmasq configurations. Has a dependency on pihole.package.

Generates a TLS certificate + key for PiHole. Depends on pihole.package.

Manages PiHole adlists and updates the gravity database. Has a dependency on pihole.service.

Manages PiHole blacklist entries. Has a dependency on pihole.service.

Manages PiHole custom CNAME entries. Has a dependency on pihole.service.

Manages PiHole local DNS A/AAAA entries. Has a dependency on pihole.service.

Manages PiHole groups. Has a dependency on pihole.service.

Manages PiHole whitelist entries. Has a dependency on pihole.service.

Starts the pihole-FTL service and enables it at boot time. Has a dependency on pihole.config.

Configure and enable TLS for PiHole (lighttpd). Has a dependency on pihole.package.

Meta-state.

Undoes some operations performed in the pihole meta-state in reverse order, i.e. removes TLS configuration from lighttpd, stops the service, removes the configuration. The package cannot be uninstalled automatically.

This state will fail. PiHole currently cannot be removed without user interaction. Has a dependency on pihole.config.clean.

Removes the PiHole, pihole-FTL and custom dnsmasq configurations and has a dependency on pihole.service.clean.

Removes generated PiHole TLS certificate + key. Depends on pihole.service.clean.

Removes managed PiHole adlists. This does not restart PiHole on its own. To apply, you will need to restart manually.

Removes managed PiHole blacklist entries. This does not restart PiHole on its own. To apply, you will need to restart manually.

Removes managed PiHole custom CNAME entries. This does not restart PiHole on its own. To apply, you will need to restart manually.

Removes managed PiHole local DNS A/AAAA entries. This does not restart PiHole on its own. To apply, you will need to restart manually.

Removes managed PiHole groups. This does not restart PiHole on its own. To apply, you will need to restart manually.

Removes managed PiHole whitelist entries. This does not restart PiHole on its own. To apply, you will need to restart manually.

Stops the pihole-FTL service and disables it at boot time.

Removes TLS configuration from lighttpd.

Commit messages

Commit message formatting is significant!

Please see How to contribute for more details.

pre-commit

pre-commit is configured for this formula, which you may optionally use to ease the steps involved in submitting your changes. First install the pre-commit package manager using the appropriate method, then run bin/install-hooks and now pre-commit will run automatically on each git commit.

$ bin/install-hooks
pre-commit installed at .git/hooks/pre-commit
pre-commit installed at .git/hooks/commit-msg

State documentation

There is a script that semi-autodocuments available states: bin/slsdoc.

If a .sls file begins with a Jinja comment, it will dump that into the docs. It can be configured differently depending on the formula. See the script source code for details currently.

This means if you feel a state should be documented, make sure to write a comment explaining it.

Linux testing is done with kitchen-salt.

Requirements

  • Ruby
  • Docker
$ gem install bundler
$ bundle install
$ bin/kitchen test [platform]

Where [platform] is the platform name defined in kitchen.yml, e.g. debian-9-2019-2-py3.

bin/kitchen converge

Creates the docker instance and runs the pihole main state, ready for testing.

bin/kitchen verify

Runs the inspec tests on the actual instance.

bin/kitchen destroy

Removes the docker instance.

bin/kitchen test

Runs all of the stages above in one go: i.e. destroy + converge + verify + destroy.

bin/kitchen login

Gives you SSH access to the instance for manual testing.