OpenMediaVault : Maintain entries in /etc/hosts

I struggled to be able to maintain my own /etc/hosts entries on OpenMediaVault.
For various reasons, this file is “controlled” by OMV, but there is no menu in the interface to customize its entries…
Moreover, there is no notion of “section” within the /etc/hosts file, where we could imagine OMV to be in full control of one, versus another section where we could maintain manually our entries…

So, I found this solution (after a while of browsing through Internet forums):
1. Create your own file (/etc/hosts2)
2. Create a SLS file that is used during /etc/hosts reconstruction

This file should be like this:
Filename : /srv/salt/omv/deploy/hosts/20myentries.sls
Content:

{% set hosts = salt['cmd.shell']('cat /etc/hosts2') %}
append_custom_hosts:
file.append:
- name: "/etc/hosts"
- text: "{{ hosts }}"

Expected outcome : each time the /etc/hosts is re-constructed by OMV, your specific file (/etc/hosts2) is appended to it…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.