file_line and multiline block

asked 2018-03-01 13:50:01 -0600

fastpuppet gravatar image

Stuck on puppet 3.8.6 (RedHat Satellite latest version), so anything involving future parser is out. I want to manage a small section of a file using puppet, i.e. NOT template the entire file because it is not fully created/managed by Puppet.

The solution below is not idempotent, despite the regex match matching the block:

$ohasd_path = '/etc/rc.d/init.d/ohasd' 
$ohasd_string = "### BEGIN INIT INFO
  # Provides: ohasd
  # Required-Start: oracleasm
  # Defalt-Start: 3 5
  # Default-Stop: 0 1 2 4 6
  # Description: Control script for the Oracle HA Services daemon
  ### END INIT INFO"

  file_line {
    'Add dependency for oracleasm in ohasd':
      line    => $ohasd_string,
      after   => '#!/bin/sh.*',
      match   => '^### BEGIN INIT INFO(\n.*)*### END INIT INFO',
      replace => true,
      multiple => false,
      path    => $ohasd_path,
      notify  => Exec['reload_systemd_units'],
  }

With ansible, this can be done using blockinfile option, I do not believe something similar exists for puppet. I really want to avoid creating a file_line resource for each line in this block and then chaining them together using the after command.

edit retag flag offensive close merge delete