Skip to content
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

Cannot declare both php and php::cli classes #489

Closed
sunnz opened this issue Oct 20, 2018 · 4 comments · Fixed by #491
Closed

Cannot declare both php and php::cli classes #489

sunnz opened this issue Oct 20, 2018 · 4 comments · Fixed by #491

Comments

@sunnz
Copy link
Contributor

sunnz commented Oct 20, 2018

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 5.x
  • Distribution: CentOS 7.x
  • Module version: 6.0.1

How to reproduce (e.g Puppet code you use)

class profile::php {
  class { '::php':
    ensure       => latest,
    manage_repos => false,
    fpm          => true,
    dev          => true,
    composer     => true,
    pear         => true,
    phpunit      => false,
    settings => {
      'PHP/max_execution_time' => '60',
      'PHP/memory_limit'       => '256M',
    },
  }

  class { '::php::cli':
    settings => {
      'PHP/max_execution_time' => '0',
      'PHP/memory_limit'       => '1000M',
    },
  }
}

What are you seeing

Duplicate declaration: Class[Php::Cli] is already declared.

What behaviour did you expect instead

max_execution_time set to 60 and memory_limit set to 256M in /etc/php.ini and /etc/php-fpm.ini.

max_execution_time set to 0 and memory_limit set to 1000M in /etc/php-cli.ini.

Output log

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Class[Php::Cli] is already declared at (file: /etc/puppetlabs/code/environments/production/modules/php/manifests/init.pp, line: 164); cannot redeclare (file: /etc/puppetlabs/code/environments/production/site/profile/manifests/php.pp, line: 16) (file: /etc/puppetlabs/code/environments/production/site/profile/manifests/php.pp, line: 16, column: 3) on node test-web

Any additional information you'd like to impart

It seems like php::cli is being declared inside php class, so I cannot redeclare it. But the php class just pass the same options to php::cli.

How do I specify default settings for PHP and only override some of those for PHP CLI?

@sunnz sunnz changed the title Cannot declare both php and php::cli class Cannot declare both php and php::cli classes Oct 20, 2018
@sunnz
Copy link
Contributor Author

sunnz commented Oct 20, 2018

Currently my workaround is as follows:

class profile::php {
  class { '::php':
    ensure       => latest,
    manage_repos => false,
    fpm          => true,
    dev          => true,
    composer     => true,
    pear         => true,
    phpunit      => false,
    settings => {
      'PHP/max_execution_time' => '60',
      'PHP/memory_limit'       => '256M',
    },
  }
  -> ini_setting { 'php/cli/memory_limit':
    ensure  => present,
    path    => '/etc/php-cli.ini',
    section => 'PHP',
    setting => 'memory_limit',
    value   => '1000M',
  }
}

The downside is that Puppet now writes 256M and then rewrites 1000M on every run.

@bastelfreak
Copy link
Member

Hi @sunnz, we currently don't support different settings for CLI vs non-CLI. Are you interested in providing a patch for this?

@sunnz
Copy link
Contributor Author

sunnz commented Oct 21, 2018

Sure! How about adding an extra cli_settings parameter to the main php class to support this?

For example, then I would use it like:

class profile::php {
  class { '::php':
    ensure       => latest,
    manage_repos => false,
    fpm          => true,
    dev          => true,
    composer     => true,
    pear         => true,
    phpunit      => false,
    settings => {
      'PHP/max_execution_time' => '60',
      'PHP/memory_limit'       => '256M',
    },
    cli_settings => {
      'PHP/memory_limit'       => '1000M',
    },
  }
}

@sunnz
Copy link
Contributor Author

sunnz commented Oct 21, 2018

Please see patch: https://github.com/voxpupuli/puppet-php/commit/97ae907c969e0d7897fd26e7abff0142e7ddbae5.diff

Which I have created a pull request #491 for it too.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants