Search code examples
linuxbashpuppetaugeas

Why does the file name needs to be repeated?


If I do

augtool --noautoload --transform "sshd incl /etc/ssh/sshd_config" ls "/files/etc/ssh/sshd_config/"

then I get the tree structure of /etc/ssh/sshd_config, but here I have written the file path twice, where the last time it is prefixed with /files.

Question

Would it be possible to do the same, but only specify the file path ones?


Solution

  • By default, Augeas loads all the files it knows about, which can be quite slow.

    To prevent this, your command uses --noautoload which bypasses automatically loading files from lenses. While this makes Augeas much faster, it also means it doesn't know about /etc/ssh/sshd_config anymore, so you need to map this file to the Sshd.lns lens manually again, which is done with --transform Sshd.lns incl /etc/ssh/sshd_config.

    Here is another possibility (from augeas-sandbox) to load any file known to Augeas and bypass other lenses:

    #!/bin/sh
    
    FILE=$1
    
    if [ -z "$FILE" ]; then
      echo "Usage: $0 <FILE>"
      exit 1
    fi
    
    augtool -L -i <<EOF
    rm /augeas/load/*["$FILE"!~glob(incl) or "$FILE"=~glob(excl)]
    load
    set /augeas/context /files$FILE
    EOF
    

    This script will use autoload statements so you don't have to specify which lens to use, but it will only load the lens you want for your file, making Augeas faster. Additionally, it sets /augeas/context, so you can use relative paths:

    $ augloadone /etc/ssh/sshd_config
    rm : /augeas/load/*["/etc/ssh/sshd_config"!~glob(incl) or "/etc/ssh/sshd_config"=~glob(excl)] 1158
    augtool> ls .