Ask Your Question
0

What is the reason for syntax error in this file ?

asked 2017-09-01 04:56:35 -0600

shajics gravatar image

updated 2017-09-01 07:46:06 -0600

DarylW gravatar image

.

root@nsa:~# puppet agent -t
    Info: Retrieving plugin
    Info: Loading facts in /var/lib/puppet/lib/facter/puppet_settings.rb
    Info: Loading facts in /var/lib/puppet/lib/facter/package_provider.rb
    Info: Loading facts in /var/lib/puppet/lib/facter/service_provider.rb
    Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb
    Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb
    Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb
    Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Syntax error at 'enabled'; expected ')' at /etc/puppet/modules/mysql/manifests/service.pp:2 on node nsa
    Warning: Not using cache on failed catalog
    Error: Could not retrieve catalog; skipping run
    root@nsa:~#


####################

root@master:/etc/puppet/modules/mysql/manifests# cat service.pp
class mysql::service (
  enabled,
  ensure,
)
{

  service { 'cswmysql5':
    ensure     => $ensure,
    hasstatus  => true,
    hasrestart => true,
    enabled    => $enabled,
    require    => Class['mysql::config'],
  }
}
root@master:/etc/puppet/modules/mysql/manifests#

Any help would be much appreaciated

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2017-09-01 05:31:18 -0600

The reason for the syntax error is a syntax error. See the documentation on “classes” about their syntax.

class mysql::service (
  Optional[Boolean]                            $enabled = undef,
  Variant[Enum['stopped', 'running'], Boolean] $ensure  = undef,
) {
  service { 'cswmysql5':
    ensure     => $ensure,
    hasstatus  => true,
    hasrestart => true,
    enabled    => $enabled,
    require    => Class['mysql::config'],
  }
}

You gotta write a dollar sign $ in front of each parameter name in the parameter list.

edit flag offensive delete link more
0

answered 2017-09-01 05:38:05 -0600

shajics gravatar image

updated 2017-09-01 07:46:56 -0600

DarylW gravatar image

My puppet version:

root@master:/etc/puppet/modules/mysql/manifests# puppet --version
3.8.7

Here is the full code from my module:

root@master:/etc/puppet/modules/mysql/manifests# cat init.pp
class mysql (
  $group = 'mysql',
  $service_enabled  = true,
  $service_running  = true,
  $user = 'mysql'
)
{
  class { 'mysql::install':
    user  => $user,
    group => $group,
  }
  class { 'mysql::config':
    user  => $user,
    group => $group,
  }
  class { 'mysql::service':
    ensure  => $service_running,
    enabled => $service_enabled,
  }
}
root@master:/etc/puppet/modules/mysql/manifests# cat install.pp
class mysql::install (
  $user,
  $group
){
  $mysql_pkgs = ['mysql5',
                 'mysql5client',
                 'mysql5rt',
                 'mysql5test',
                 'mysql5devel' ]

  package { $mysql_pkgs:
    ensure  => present,
    require => User[$user],
  }

  user { $user:
    ensure     => present,
    comment => 'MySQL user',
    gid           => $group,
    shell         => '/bin/false',
    require     => Group[$group],
  }

  group { $group:
    ensure => present,
  }
}
root@master:/etc/puppet/modules/mysql/manifests# cat config.pp
class mysql::config (
  $user,
  $group,
){
  file { '/opt/csw/mysql5/my.cnf':
    ensure  => present,
    source  => 'puppet:///modules/mysql/my.cnf',
    owner   => $user,
    group    => $group,
    require  => Class['mysql::install'],
    notify     => Class['mysql::service'],
  }

  file { '/opt/csw/mysql5/var':
    group     => $user,
    owner    => $group,
    recurse  => true,
    require   => File['/opt/csw/mysql5/my.cnf'],
  }
}

root@master:/etc/puppet/modules/mysql/manifests# cat service.pp
class mysql::service (
  enabled,
  ensure,
){

  service { 'cswmysql5':
    ensure     => $ensure,
    hasstatus  => true,
    hasrestart => true,
    enabled    => $enabled,
    require    => Class['mysql::config'],
  }
}
edit flag offensive delete link more

Comments

a) You're using some _old_ Puppet version, aren't you? b) It has to read `enable` of course (not `enable_d_`): see https://docs.puppet.com/puppet/latest/types/service.html#service-attribute-enable

Kai Burghardt gravatar imageKai Burghardt ( 2017-09-01 05:54:13 -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

Stats

Asked: 2017-09-01 04:56:35 -0600

Seen: 78 times

Last updated: Sep 01