Skip to content

Added replace attribute #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

WhatsARanjit
Copy link
Contributor

We have a use case where a Solaris /etc/logadm.conf file has entries like:

/var/adm/wtmpx -C 3 -P 'Sun Apr 26 07:10:04 2015' -g adm -m 644 -o adm -p 1m -t '/var/adm/oldlogs/wtmpx-$nodename-%Y%m%d' -z 0

Using the shell command to add entries by design puts a timestamp in the line. A customer would like to manage lines of this file. Using file_line and the match attribute causes the line to be continually updated with new timestamp.

$timestamp = chomp(generate('/bin/date', '+%a %b %d %T %Y'))
$wtmpx_regex = '\/var\/adm\/wtmpx \-C \d+ \-P \'[\w\s:]+\''

file_line { 'wtmpx':
  path    => '/tmp/logadm.conf',
  line    => "/var/adm/wtmpx -C 3 -P '${timestamp}' -g adm -m 644 -o adm -p 1m -t '/var/adm/oldlogs/wtmpx-\$nodename-%Y%m%d' -z 0A",
  match   => $wtmpx_regex,
}

The time stamp will be different for each system because it is the time the entry was added.

@WhatsARanjit
Copy link
Contributor Author

@elyscape
Copy link
Contributor

elyscape commented May 7, 2015

As I mentioned on the previous PR, this PR and the issue need some work. I'll elaborate on my concerns when I get back to a keyboard.

@elyscape
Copy link
Contributor

elyscape commented May 7, 2015

In the meantime, instead of using file_line to manage your logadm.conf, I'd recommend instead using something like this custom logadm type.

@WhatsARanjit
Copy link
Contributor Author

@elyscape Yeah saw that, it could be a type that works. But in absence of a provider and spec testing I opted to add an attribute to file_line. I'll look into it though.

@elyscape
Copy link
Contributor

elyscape commented May 8, 2015

Not all types use providers. That custom logadm type is an example of such a type.

@puppet-community-ci
Copy link

The result of the test was: PASS
Details at http://planck.nibalizer.com/buildlogs/puppetlabs+puppetlabs-stdlib+451+1432905358+PASS

I am a beta ci bot. I am probably lying to you.
You can contact nibalizer for more details.

@nibalizer
Copy link
Contributor

It seems to me like the problem here is managing logadm.conf. Logadm, it seems, is one of those terrible daemons that writes back to its own config file. However, I think I have a solution. From the logadm docs:

By specifying -p now as a rotation condition, a log rotation is forced.

Setting -p now and removing -P then all files will be rotated whenever logadm is invoked by cron. This means that cron can handle scheduling and puppet can manage logadm.conf idempotently.

@puppet-community-ci
Copy link

The result of the test was: PASS
Details at http://ci.puppet.community/buildlogs/puppetlabs+puppetlabs-stdlib+451+1433017216+PASS

I am a beta ci bot. I am probably lying to you.
You can contact nibalizer for more details.

@DavidS
Copy link
Contributor

DavidS commented Jun 1, 2015

Hi @WhatsARanjit ,

thank you for your patch, I think it's a worth-while addition.

To be acceptable to stdlib, this needs at least a short description in the README and a unit test in spec/unit//puppet/provider/file_line/ruby_spec.rb.

Like the file#replace parameter, this should default to true to keep existing configurations running. Also, I have the impression, that the replace as implemented works exactly inverse to what the file type's version does. Please verify that too.

Cheers, D.

@puppet-community-ci
Copy link

The result of the test was: PASS
Details at http://planck.nibalizer.com/buildlogs/puppetlabs+puppetlabs-stdlib+451+1433192244+PASS

I am a beta ci bot. I am probably lying to you.
You can contact nibalizer for more details.

@puppet-community-ci
Copy link

The result of the test was: PASS
Details at http://ci.puppet.community/buildlogspuppetlabs+puppetlabs-stdlib+451+1433256065+PASS

I am a beta ci bot. I am probably lying to you.
You can contact nibalizer for more details.

@underscorgan
Copy link
Contributor

@WhatsARanjit ping? any update on this?

@bmjen
Copy link
Contributor

bmjen commented Jul 30, 2015

Merged in #494

@bmjen bmjen closed this Jul 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants