Skip to content

Instantly share code, notes, and snippets.

@xorpaul
Created November 27, 2013 15:27
Show Gist options
  • Save xorpaul/7677565 to your computer and use it in GitHub Desktop.
Save xorpaul/7677565 to your computer and use it in GitHub Desktop.
Augeas Puppet Provider setm method debug

This works, when calling it directly:

augtool> print /files/etc/ssh/sshd_config/PermitRootLogin
/files/etc/ssh/sshd_config/PermitRootLogin[1] = "yes"
/files/etc/ssh/sshd_config/PermitRootLogin[2] = "yes"
/files/etc/ssh/sshd_config/PermitRootLogin[3] = "yes"
augtool> setm /files/etc/ssh/sshd_config/ PermitRootLogin no
augtool> print /files/etc/ssh/sshd_config/PermitRootLogin
/files/etc/ssh/sshd_config/PermitRootLogin[1] = "no"
/files/etc/ssh/sshd_config/PermitRootLogin[2] = "no"
/files/etc/ssh/sshd_config/PermitRootLogin[3] = "no"

But when I try to use this in a puppet manifest:

  augeas { 'configure_sshd':
    context  => '/files/etc/ssh/sshd_config',
    changes  =>  [ 'set PasswordAuthentication no',
      'setm PermitRootLogin no',
    ],
  }

it errors with

err: /Stage[main]//Node[foobar]/Augeas[configure_sshd]: Could not evaluate: missing string argument 3 for setm
@xorpaul
Copy link
Author

xorpaul commented Nov 27, 2013

The problem was that I was using libaugeas-ruby package version 0.3.0 and setm need 0.4.0

I also tried last() option, because only the last found setting in the sshd config gets used.

It works in augtool directly:

augtool> print /files/etc/ssh/sshd_config/PermitRootLogin
/files/etc/ssh/sshd_config/PermitRootLogin[1] = "yes"
/files/etc/ssh/sshd_config/PermitRootLogin[2] = "yes"
/files/etc/ssh/sshd_config/PermitRootLogin[3] = "yes"
augtool> set /files/etc/ssh/sshd_config/PermitRootLogin[last()] no
augtool> print /files/etc/ssh/sshd_config/PermitRootLogin
/files/etc/ssh/sshd_config/PermitRootLogin[1] = "yes"
/files/etc/ssh/sshd_config/PermitRootLogin[2] = "yes"
/files/etc/ssh/sshd_config/PermitRootLogin[3] = "no"

and in puppet:

  augeas { 'configure_sshd':
    context  => '/files/etc/ssh/sshd_config',
    changes  =>  [ 'set PasswordAuthentication no',
      'set PermitRootLogin[last()] no',
    ],
  }

results in:

 PermitRootLogin yes
-PermitRootLogin yes
+PermitRootLogin no

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment