Request: OMV only partially rewrite /etc/hosts

  • Hi,


    Today, OMV is fully managing /etc/hosts, which means we cannot define custom entries into it. A solution mentioned in this thread suggests to change things at the DNS server level (in dnsmasq or whatever DNS server is used), but this is not always doable or recommendable.


    Would it be possible that OMV scripts only change /etc/hosts within some markers within the file? I think OMV already does that in some other file (sorry, can't remember which) where the content is only reset between the two lines # <<<< and # >>>>, letting the other user-specific lines unchanged.


    Thank you!

  • votdev

    Added the Label resolved
  • votdev

    Added the Label OMV 5.x
  • So nice, so powerful... Thank you votdev . Yet, my original suggestion looks a little simplier. What do you think about it? Or you may have so many things to do...


    For memo (if others were looking for it), a file where OMV is partially writing is /etc/fstab, where the OMV-written part is enclosed between

    Code
    # >>> [openmediavault]
    [... bla bla bla]
    
    # <<< [openmediavault]
    [here, is your own fstab mounts]
    • Official Post

    you could just a file (/srv/salt/omv/deploy/hosts/20myentries.sls) like the following and then maintain your entries in /etc/hosts2


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

    omv 6.1.1-1 Shaitan | 64 bit | 5.19 proxmox kernel | plugins :: omvextrasorg 6.1.1 | kvm 6.2.5 | compose 6.3 | mergerfs 6.3.4 | zfs 6.0.12
    omv-extras.org plugins source code and issue tracker - github


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

    Edited once, last by ryecoaaron ().

  • you could just a file (/srv/salt/omv/deploy/hosts/20myentries.sls) like the following and then maintain your entries in /etc/hosts2

    Does anything else need to be done to make this take effect?

    --
    Google is your friend and Bob's your uncle!


    OMV AMD64 6.x on headless Chenbro NR12000 1U 1x 8m Quad Core E3-1220 3.1GHz 16GB ECC RAM.

    • Official Post

    Thanks, just the info I needed for this problem:

    No it isn't. You will break apt-get update if the repo file points to an invalid ip. Just: sudo truncate -s 0 /etc/apt/sources.list.d/vscode.list

    RE: Microsoft repo installed on all Raspberry Pi’s

    omv 6.1.1-1 Shaitan | 64 bit | 5.19 proxmox kernel | plugins :: omvextrasorg 6.1.1 | kvm 6.2.5 | compose 6.3 | mergerfs 6.3.4 | zfs 6.0.12
    omv-extras.org plugins source code and issue tracker - github


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • No it isn't. You will break apt-get update if the repo file points to an invalid ip. Just: sudo truncate -s 0 /etc/apt/sources.list.d/vscode.list

    RE: Microsoft repo installed on all Raspberry Pi’s

    Thanks, I first commented out the active line in that file, I just believe in belt and suspenders where some companies are involved. If it breaks apt update, I'll know it got reactivated without my knowledge or permission.

  • @ryecoaaron : your code is missing double quotes around the {{ hosts }} variable. It should be:


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

    Without them, I get the error message: Rendering SLS 'base:omv.deploy.hosts.20perso_hosts2' failed: could not find expected ':'

    • Official Post

    your code is missing double quotes around the {{ hosts }} variable. It should be:

    Sorry, i was just writing a snippet off the top of my head. I didn't test it.

    omv 6.1.1-1 Shaitan | 64 bit | 5.19 proxmox kernel | plugins :: omvextrasorg 6.1.1 | kvm 6.2.5 | compose 6.3 | mergerfs 6.3.4 | zfs 6.0.12
    omv-extras.org plugins source code and issue tracker - github


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • The hosts2 solution looks ideal, but unfortunately the newlines are not maintained; I guess reading it into a variable and then outputting again loses them.


    However this seems to work fine:

    Code
    append_custom_hosts:
        file.append:
            - name: "/etc/hosts"
            - source: "/etc/hosts2"


    I'm no Salt expert so there may be some hidden gotchas to that.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!