Puppet – The Augeas resource type

In the previous demo, we saw how to makd a change via the command line. We used the “/etc/hosts” file as the example. We’ll now show you how to make the same change, but this time with the augeas puppet resource.

You can therefore do the same thing as via the command line using the following resource:

  augeas{"hostfile" :
    context    => "/files/etc/hosts/3/",
    changes  => "set ipaddr 8.8.8.8",
  }

If you want to append to a file, then you need to create a new node. You can achieve this using the last() function.

the “/etc/sudoers” file

Let’s say you want to add the following line to your /etc/sudoers file:

Defaults:tom !requiretty
tom ALL = (ALL) ALL

This can be achieved using the following resource:

  augeas { "sudotom":
    context => "/files/etc/sudoers",
    changes => [
      "set Defaults[type=':tom']/type :tom",
      "set Defaults[type=':tom']/requiretty/negate ''",
      "set spec[user = 'tom']/user tom",
      "set spec[user = 'tom']/host_group/host ALL",
      "set spec[user = 'tom']/host_group/command ALL",
      "set spec[user = 'tom']/host_group/command/runas_user ALL",
    ],
  }

See also:
https://docs.puppetlabs.com/guides/augeas.html