FAQ
I have a module located at /etc/puppet/environments/test/modules/ruby.
I
n this I have a manifests folder with two .pp files - init.pp and
gemInstall.pp.

In one of my node def files I have:

include ruby

ruby::gemInstall { 'someGem-version.gem':
path => '/path/to/agent/local/gem/repo',
}

ruby::gemInstall is a define, and it has some logic to get around some
problems I had when trying to install gems via a package resource, the
source is below.

define ruby::gemInstall (
gem = $title,
path = hiera('v_rubygem_path')

) {
$gemName = regsubst($gem, '([^-]+)-.*\.gem', '\1')

exec {"/usr/local/bin/gem install ${gem}":
cwd => $path,
unless => "gem list -i ${gemName}",
require => Package['rubygems'];
}
}

But when I try to apply this, I get the following:

err: Could not retrieve catalog from remote server: Error 400 on SERVER:
Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid
resource type ruby::gemInstall at
/etc/puppet/environments/test/manifests/nodes/MyNodeDef.pp:84 on node XX

Am I doing something wrong when it comes to auto-loading classes and
defines, or is this an instance of this bug
(http://projects.puppetlabs.com/issues/13858) cropping up?

Thanks.


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/NBiTSrN-8PQJ.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Search Discussions

  • Llowder at Jun 27, 2012 at 8:14 pm
    A few updates, comment inline with original post.
    On Wednesday, June 27, 2012 11:12:15 AM UTC-5, llo...@oreillyauto.com wrote:

    I have a module located at /etc/puppet/environments/test/modules/ruby.
    I
    n this I have a manifests folder with two .pp files - init.pp and
    gemInstall.pp.

    In one of my node def files I have:

    include ruby

    ruby::gemInstall { 'someGem-version.gem':
    path => '/path/to/agent/local/gem/repo',
    }

    ruby::gemInstall is a define, and it has some logic to get around some
    problems I had when trying to install gems via a package resource, the
    source is below.
    I refactored and made some changes in testing a few things, current version
    is:

    define ruby::gemInstall (
    r_gem = $name,
    r_path = hiera('v_rubygem_path')
    ){

    r_gemName = regsubst($r_gem, '([^-]+)-.*\.gem', '\1')

    exec { "gem_install_${r_gemName}":
    command => "/usr/local/bin/gem install ${r_gemName}",
    cwd => $r_path,
    unless => "gem list -i ${r_gemName}",
    require => Package['rubygems'],
    }
    }


    But when I try to apply this, I get the following:

    err: Could not retrieve catalog from remote server: Error 400 on SERVER:
    Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid
    resource type ruby::gemInstall at
    /etc/puppet/environments/test/manifests/nodes/MyNodeDef.pp:84 on node XX

    Am I doing something wrong when it comes to auto-loading classes and
    defines, or is this an instance of this bug (
    http://projects.puppetlabs.com/issues/13858) cropping up?

    I've also ran puppet-lint against this file, and it thinks /all/ the
    variables are "top-scope variable being used without an explicit namespace"
    . One of my coworkers looked at this, and thinks it is a syntax error of
    some sort. The puppet-lint results make me think that too, but for the life
    of me I can't find what it is.

    Also, I don't think it is that bug I referenced because I have several
    other defines in different modules that work perfectly.

    Thanks.
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/l4v2zxG2Pc0J.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Felix Frank at Jun 28, 2012 at 7:24 am
    Hi,

    I don't really know how this even compiles, but here's what I think
    needs changin.

    Before you go on with this - do you have pressing reasons for not using
    package { "gemname": provider => "gem" } ?
    On 06/27/2012 10:14 PM, llowder@oreillyauto.com wrote:
    define ruby::gemInstall (
    r_gem = $name,
    $r_gem = $name,
    r_path = hiera('v_rubygem_path')
    $r_path = ...
    ){

    r_gemName = regsubst($r_gem, '([^-]+)-.*\.gem', '\1')
    $r_gemName = ...
    exec { "gem_install_${r_gemName}":
    command => "/usr/local/bin/gem install ${r_gemName}",
    cwd => $r_path,
    unless => "gem list -i ${r_gemName}",
    require => Package['rubygems'],
    }
    }
    HTH,
    Felix

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Llowder at Jun 28, 2012 at 1:15 pm

    On Thursday, June 28, 2012 2:24:08 AM UTC-5, Felix.Frank wrote:
    Hi,

    I don't really know how this even compiles, but here's what I think
    needs changin.
    That may have been an issue, but it still doesn't work. I get the same
    error.


    Before you go on with this - do you have pressing reasons for not using
    package { "gemname": provider => "gem" } ?
    That provider is not available on this system, I tried that first.


    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/o-HCH5IyCRMJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Felix Frank at Jun 28, 2012 at 1:29 pm

    On 06/28/2012 03:15 PM, llowder@oreillyauto.com wrote:


    On Thursday, June 28, 2012 2:24:08 AM UTC-5, Felix.Frank wrote:

    Hi,

    I don't really know how this even compiles, but here's what I think
    needs changin.


    That may have been an issue, but it still doesn't work. I get the same
    error.
    Then I shall go on a limb an suggest you forego camel-case (*cringe*)
    and rename to ruby::gem_install, see if that helps. Otherwise I'd be
    grateful for yet another verbatim copy of your defined type, also the
    information in which manifest file the type declaration resides.
    Before you go on with this - do you have pressing reasons for not using
    package { "gemname": provider => "gem" } ?


    That provider is not available on this system, I tried that first.
    I suppose the provider in and of itself is included in your puppet
    distribution (anything else would be madness).
    It makes sense that it won't work, seeing as your gem binary is
    installed in /usr/local.
    What does *not* compute is the fact that you are in fact installing a
    "rubygems" package. Huh? Is this package installing binaries to
    /usr/local? Are there other reasons for gem being installed there?

    I would still try and go for a working gem provider, but be that as it
    may, your defined type really Should Work.

    Regards,
    Felix

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Llowder at Jun 28, 2012 at 3:22 pm

    On Thursday, June 28, 2012 8:29:25 AM UTC-5, Felix.Frank wrote:
    Then I shall go on a limb an suggest you forego camel-case (*cringe*)
    and rename to ruby::gem_install, see if that helps. Otherwise I'd be
    grateful for yet another verbatim copy of your defined type, also the
    information in which manifest file the type declaration resides.
    define ruby::gem_install (
    $r_gem = $name,
    $r_path = hiera('v_rubygem_path')
    ){

    $r_gemName = regsubst($r_gem, '([^-]+)-.*\.gem', '\1')

    exec { "gem_install_${r_gem}":
    command => "/usr/local/bin/gem install ${r_gem}",
    cwd => $r_path,
    unless => "gem list -i ${r_gemName}",
    require => [ Package['rubygems'], File['gem_repo'] ],
    }
    }


    This works, but it appears to be executing for the whole list of gems I am
    passing it, even though those gems are already installed and the unless
    command should prevent it. But that's another matter that I should be able
    to figure out on my own.

    I did some other testing, and I noticed something that took me off guard
    and ready to file a bug report, though after a little research seems to at
    least be somewhat documented as intended behavior.

    I was trying to debug why it was still running the install command, so I
    changed my define slightly:

    define ruby::gem_install (
    $r_gem = $name,
    $r_path = hiera('v_rubygem_path')
    ){

    $r_gemName = regsubst($r_gem, '([^-]+)-.*\.gem', '\1')
    $r_gemVer = regsubst($r_gem, '[^-]+-(.*)\.gem', '\1')
    notify{"notify_1_${r_gem}":
    message => "r_path is: ${r_path} || r_gem is: ${r_gem} || r_gemName is:
    ${r_gemName} || r_gemVer is: ${r_gemVer}",
    }
    }

    This has all the expected values, and it lives in
    /etc/puppet/environments/test/modules/ruby/manifests/gem_install.pp.

    I then copied the file, renamed it to
    /etc/puppet/environments/test/modules/ruby/manifests/gemInstall.pp.

    I changed the first line, and ONLY the first line to:

    define ruby::gemInstall (

    In my node def I am working on, I have the following:

    ruby::gem_install { 'actionmailer':
    r_gem => 'actionmailer-3.1.3.gem',
    r_path => hiera('v_rubygem_path'),
    }

    ruby::gemInstall { 'actionmailer':
    r_gem => 'actionmailer-3.1.3.gem',
    r_path => hiera('v_rubygem_path'),
    }


    And I get the following (same error as before):

    err: Could not retrieve catalog from remote server: Error 400 on SERVER:
    Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid
    resource type ruby::gemInstall at
    /etc/puppet/environments/test/manifests/nodes/MyTestNodeDef.pp:69 on node X


    I could have sworn I saw something that said acceptable names for
    classes/defines/variables was [a-z][a-zA-Z0-9]*, but when I went looking
    what I found was instead:

    "Class names, module names, and the names of defined and custom resource
    types should be restricted to lowercase alphanumeric characters and
    underscores, and should begin with a lowercase letter; that is, they should
    match the expression [a-z][a-z0-9_]*. Although some names that violate
    these restrictions currently work, using them is not recommended."

    But this was somewhat buried in the Language Guide
    (http://docs.puppetlabs.com/guides/language_guide.html), and I (later)
    found something along the same lines at
    http://docs.puppetlabs.com/puppet/2.7/reference/modules_fundamentals.html.

    The Style Guide (http://docs.puppetlabs.com/guides/style_guide) only says
    "When defining variables you should only use letters, numbers and
    underscores. You should specifically not make use of dashes." and makes no
    mention of not using camelCase. This document also makes no mention of case
    restrictions on class and define names.

    From the tutorial section on defines
    (http://docs.puppetlabs.com/learning/definedtypes.html) no mention of an
    all lowercase requirement is made at all, though all examples are in all
    lowercase. Then again, none of the examples would be cases where people are
    likely to have wanted to use mixed case.

    On a second reading of the tutorial I did find a brief mention that class
    names have to be all lowercase, which I seem to have missed.

    The other rather interesting thing is that when I had my define in the same
    file as a class definition, it worked as expected. It was only after I
    moved the defines to their own files (as per the style guide) that I
    started having this problem.

    So... long story short, this is the second time in two weeks I am having to
    refactor all my code in order to prepare for a point release upgrade.

    While the overall software is very nice, and the support I have received
    when I have needed it has been very helpful, I am less than happy with this
    software right now.

    And while I do recognize that both rewrites could have been avoided with a
    more careful reading of the documentation, I and my team should not have to
    pick through the documentation line by line like it was some sort of
    contract I was getting ready to sign.

    For what it is worth, I think the forcing of all lowercase
    variables/classes/defines/modules is serious design flaw - even worse than
    not allowing hyphens, which I consider to be a pretty serious flaw (and
    from reading this list and various other bug reports, a lot of people agree)

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/VvJcDmhkKXEJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Felix Frank at Jun 29, 2012 at 7:47 am
    Hi,
    On 06/28/2012 05:22 PM, llowder@oreillyauto.com wrote:
    This works, but it appears to be executing for the whole list of gems I
    am passing it, even though those gems are already installed and the
    unless command should prevent it. But that's another matter that I
    should be able to figure out on my own.
    I noticed that in your unless parameter, you use "gem" without a path.
    It's possibly always failing if puppet cannot find the binary.

    Please note that exec takes an actual "path" parameter as well, that you
    should use to define the search path.
    So... long story short, this is the second time in two weeks I am having
    to refactor all my code in order to prepare for a point release
    upgrade.
    Ugh, I feel your pain. Sorry for the hassle. Have you been using puppet
    for long? I believe that it really takes quite some time to find the
    best practices on one's own. The Puppet Labs style guide e.g. has helped
    me very little in that respect, personally.
    For what it is worth, I think the forcing of all lowercase
    variables/classes/defines/modules is serious design flaw - even worse
    than not allowing hyphens, which I consider to be a pretty serious flaw
    (and from reading this list and various other bug reports, a lot of
    people agree)
    I can agree about the case notion, although allowing mixed case is
    problematic in puppet: file { } and File { } are semantically different,
    so defined types cannot ever be named with a capital first letter. So
    conditionally allowing mixed case would be potentially confusing (or so
    I believe).

    About the dashes, well - I don't really see the issue. In languages like
    C, the dash has been a reserved word for decades. When the lexer sees a
    dash, it will make it a standalone token, and the parser will recognize
    it as an operator. It all adheres niceley to the KISS principle. It's my
    firm belief that making the dash stop being an operator in certain
    contexts does much more harm than good. (Specifically, in hindsight it's
    really terrible that puppet ever allowed dashes in class names.)

    Sincerely,
    Felix

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedJun 27, '12 at 4:12p
activeJun 29, '12 at 7:47a
posts7
users2
websitepuppetlabs.com

2 users in discussion

Llowder: 4 posts Felix Frank: 3 posts

People

Translate

site design / logo © 2022 Grokbase