1

I'm trying to execute the following module in Puppet this and got the error:

[root@localhost modules]# puppet apply jenkin_install.pp
Error: Could not parse for environment production: Syntax error at '8080' at /etc/puppetlabs/code/modules/jenkin_install.pp:41:52 on node localhost.localdomain

Here's the code:

 exec { 'Change the port from 8080 to 8000':
  command   => 'sed -i'.original' 's/JENKINS_PORT="8080"/JENKINS_PORT="8000"/' /etc/sysconfig/jenkins',
  path      => '/usr/local/bin/:/bin/',
  logoutput => true,
  onlyif    => 'grep "8000" /etc/sysconfig/jenkins',
  }

I'm wondering how to solve the syntax error in the command?

Thanks

med.guy
  • 11
  • 1
  • read https://puppet.com/docs/puppet/7.4/lang_data_string.html – KamilCuk Mar 12 '21 at 23:38
  • 2
    You have multiple strings for your value for the `command` attribute due to multiple quotes. Alternatively, consider using the `file_line` resource as an improvement and a fix to the resource in the question. – Matthew Schuchard Mar 13 '21 at 12:28

1 Answers1

3

The problem is that you are quoting the command string using single quotes when the command itself contain single quotes. The parser can't tell the difference between the two, so ends up interpreting bits of the command as Puppet code.

The easiest and clearest fix is to use heredoc strings:

exec { 'Change the port from 8080 to 8000':
  command   => @(END),
    sed -i'.original' 's/JENKINS_PORT="8080"/JENKINS_PORT="8000"/' /etc/sysconfig/jenkins
    | END
  path      => '/usr/local/bin/:/bin/',
  logoutput => true,
  onlyif    => 'grep "8000" /etc/sysconfig/jenkins',
}

Although, as another commenter says, this resource should be recoded as a file_line resource.

file_line { 'set_JENKINS_PORT':
  ensure => present,
  path   => '/etc/sysconfig/jenkins',
  match  => 'JENKINS_PORT=',
  line   => 'JENKINS_PORT="8000"',
}
Jon
  • 3,573
  • 2
  • 17
  • 24