init config once

17 views
Skip to first unread message

Steve McKuhr

unread,
Jan 28, 2021, 12:57:37 PM1/28/21
to Puppet Users
I'd like to initialize a user config file once, at software install time, then allow application admins to manage the file contents via web interface (add/remove users, etc.) - I have come up with the following:

file { 'users':
  ensure => present,
  content => template('my-template'),
  validate_cmd => '/bin/test ! -f users.control',
}
file { 'users.control':
  ensure => present,
  content => "puppet managed",
  require => File['users'],
}

The above code works ok, however I was wondering if there is a more elegant solution.

Thanks,
Steve

Ben Ford

unread,
Jan 28, 2021, 12:59:19 PM1/28/21
to puppet...@googlegroups.com
Yep, just use the replace attribute on the file resource. https://puppet.com/docs/puppet/latest/types/file.html#file-attribute-replace

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/fb1ae2b4-f220-4d18-864b-aafbadb44b14n%40googlegroups.com.

Martin Alfke

unread,
Jan 28, 2021, 2:07:19 PM1/28/21
to Puppet Users
and please use ensure => file !
this is more clear.
you can set the file ensure attribute to one of the following: file, directory, link, absent
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CACkW_L5oTmsHiwvmVEisKap7gkUt1P4Gmvh1-%3DBQqNtHHiWAcA%40mail.gmail.com.

Steve McKuhr

unread,
Jan 28, 2021, 8:14:08 PM1/28/21
to puppet...@googlegroups.com
I've just realized that my problem statement was slightly misleading. A
'users' file gets installed as part of the software package, and the
goal is replacing its contents during the first Puppet run. The next
Puppet runs should ignore any changes.

Steve McKuhr

unread,
Jan 28, 2021, 11:50:50 PM1/28/21
to puppet...@googlegroups.com
In an effort to avoid errors triggered by validate_cmd, I ended up using
a conditional based on a File.exists custom fact. I'm still open to
suggestions, this is all new territory to me.

Benjamin Ridley

unread,
Jan 29, 2021, 12:03:24 AM1/29/21
to puppet...@googlegroups.com
You might be better off using something like Puppet Bolt to deploy the file as a one off task at provisioning, rather than trying to manage it declaratively through Puppet. 

Martin Alfke

unread,
Jan 29, 2021, 3:14:22 AM1/29/21
to puppet...@googlegroups.com
A custom fact is the best way to report the status of the file on the node to the master and have the file managed by Puppet based on the fact value.

Bolt needs ssh access to the systems (unless you are using Puppet Enterprise which does not need ssh but uses a message queue on the master and the pxp-agent on the nodes.).

Besides this: Bolt must be executed manually

Ben Ford

unread,
Jan 29, 2021, 2:47:45 PM1/29/21
to puppet...@googlegroups.com
I do have a kind of terrible module that does exactly this.... I make no guarantees whatsoever about how well it works. I ended up not using it for much longer after building it.


Justin Stoller

unread,
Jan 31, 2021, 4:53:21 PM1/31/21
to puppet...@googlegroups.com
Just to pile on. If you want the content updated whenever the package is updated and you are managing the package with puppet you can "subscribe" to the package resource to have the file resource only applied when the package changes.

Steve McKuhr

unread,
Mar 15, 2021, 9:57:13 PM3/15/21
to puppet...@googlegroups.com
Thanks for that, it *is* useful, although not in this particular
scenario. It's sitting now in my Puppet toolbox.
Reply all
Reply to author
Forward
0 new messages