Ask Your Question

puppet - ini remove

asked 2017-05-22 14:10:04 -0600

puser gravatar image

I am using puppet 4.5.3 and ini_setting module version 1.4.2. I need to be able to remove a stanza in an ini file. For example:

ip = ''
hostname = 'myserver'
port = 80

I am able to remove each section of the ini file using the ensure => absent parameter but I cannot find a way to remove the stanza header, or preferably the whole thing in one command.

What I have left is


Does anyone know how this can be done? Unfortunately there are other stanzas in the same file that I need to keep so I cannot simply delete the file.


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-05-23 11:19:42 -0600

smarlow gravatar image

After reviewing the code it doesn't look like there is any facility to delete existing section headers. You could potentially extend ini_setting to do this as part of removing the last setting in a section, but that may be more work than you're interested in.

If you know what the rest of the content in the ini file should look like then you could manage the entire thing either via a static file or a template.

If you don't know what the rest of the content should look like but you are confident that the entire section will be removed, you could use a file_line resource from stdlib to erase the header. I'm sure you could also use augeas for that task.

edit flag offensive delete link more


how would file_line removing the header remove the sections?

puser gravatar imagepuser ( 2017-05-23 11:33:06 -0600 )edit

I imagine that you would have the ini_settings to erase the settings and then the file_line to erase the remaining section header. You can use file_line with ensure => absent to erase a line.

smarlow gravatar imagesmarlow ( 2017-05-23 11:50:00 -0600 )edit

yeah the problem with that is if there are any sections that match. But augeas clearly is the correct way.

puser gravatar imagepuser ( 2017-05-23 11:51:06 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-05-22 14:10:04 -0600

Seen: 149 times

Last updated: May 23 '17