https://www.puppet.com/community logo
Join Slack
Powered by
# puppet
  • t

    Tyler Maclean

    09/22/2022, 4:11 PM
    Is there a way to retrieve a list of all the values of a particular parameter from a collection of resources? For example, say I have
    file { "a": owner => 'Alice'}
    and
    file {'b': owner => 'Bob'}
    , can I get an array of
    ['Alice', 'Bob']
    ? I want to conditionally create some resources based on the unique set of params from another set of resources. I found a way to do it using ensure_resource from stdlib but it feels clunky and wrong.
  • h

    hbui

    09/22/2022, 4:22 PM
    I think it feels clunky and wrong because it relies on the catalog getting created in a specific order. To me this feels like you want a defined type where you know you have a variety of inputs and then you can create e.g. file a and serivce a with input of Alice and file b service b with input of Bob
  • h

    hbui

    09/22/2022, 4:23 PM
    I think it feels clunky and wrong because it relies on the catalog getting created in a specific order. To me this feels like you want a defined type where you know you have a variety of inputs and then you can create e.g. file a and serivce a with input of Alice and file b service b with input of Bob
  • r

    Robert Vincent

    09/22/2022, 4:34 PM
    @Tyler Maclean -- there is a way to write a custom fact that retrieves the values of a particular parameter from all installed resources.
  • d

    Dr Bunsen Honeydew

    09/22/2022, 4:34 PM
    tyler401 took a dive. (Karma: -1)
  • r

    Robert Vincent

    09/22/2022, 4:35 PM
    DAMN IT!!!
  • r

    Robert Vincent

    09/22/2022, 4:35 PM
    @Tyler Maclean ++
  • d

    Dr Bunsen Honeydew

    09/22/2022, 4:35 PM
    tyler401 +1! (Karma: 0)
  • r

    Robert Vincent

    09/22/2022, 4:35 PM
    (gotta get out of the habit of using double-dashes in Slack...)
  • h

    hbui

    09/22/2022, 4:38 PM
    just the puppetcommunity slack 🙂
  • t

    Tyler Maclean

    09/22/2022, 4:43 PM
    thanks for the advice
  • s

    Slackbot

    09/22/2022, 5:44 PM
    This message was deleted.
    e
    h
    j
    • 4
    • 3
  • d

    Dr Bunsen Honeydew

    09/22/2022, 5:45 PM
    goodnews 🧑‍🏫Puppet Forge is about to start up in #CFD8Z9A4T
  • s

    Slackbot

    09/22/2022, 8:23 PM
    This message was deleted.
    n
    n
    +2
    • 5
    • 22
  • n

    nate

    09/22/2022, 8:23 PM
    this is a terrible question, but i have a case where we need to install a custom fact as part of a module. this is fine. we do it all the time. due to the fact that we still have super old oses and ring versions scattered in our infrastructure, this fact needed to be compatible all the way back to ruby 1.8.7. yes, i know. the difference is one character. the version that runs everywhere else fails hard on old ruby due to option hash syntax. my workaround was to template the fact, lay it down as a file, and call it a day while we work to get rid of the old stuff. the result is that the fact gets removed at the start of an agent run and replaced soon after. how would you approach this, aside from burning it all down?
  • n

    nate

    09/22/2022, 8:24 PM
    this is a terrible question, but i have a case where we need to install a custom fact as part of a module. this is fine. we do it all the time. due to the fact that we still have super old oses and ruby versions scattered in our infrastructure, this fact needed to be compatible all the way back to ruby 1.8.7. yes, i know. the difference is one character. the version that runs everywhere else fails hard on old ruby due to option hash syntax. my workaround was to template the fact, lay it down as a file, and call it a day while we work to get rid of the old stuff. the result is that the fact gets removed at the start of an agent run and replaced soon after. how would you approach this, aside from burning it all down?
  • r

    Robert Vincent

    09/22/2022, 8:42 PM
    Try
    :option => 1
    instead of
    option: 1
    ?
  • d

    Dr Bunsen Honeydew

    09/22/2022, 8:45 PM
    waiting 🧑‍🏫PE Console is about to start up in #CFD8Z9A4T
  • s

    smortex

    09/22/2022, 9:18 PM
    You can put both code, and run one or the other depending on the version of Ruby, like for example https://github.com/puppetlabs/puppet/blob/9938cd806703904cb0069abcc5753a359f869412/lib/puppet/util.rb#L37-L45
  • n

    n3snah

    09/23/2022, 12:45 AM
    Could someone please give me an example on how to mock/stub a resource for PDK? I am struggling with finding an example on the net.
  • n

    n3snah

    09/23/2022, 12:45 AM
    Could someone please give me an example on how to mock/stub a resource for PDK? I am struggling with finding an example on the net.
  • n

    natemccurdy

    09/23/2022, 12:51 AM
    The PDK uses rspec-puppet for tests, so you should look at those docs for some examples. Here’s a good starting point: https://rspec-puppet.com/documentation/classes/#specifying-code-to-include-before
  • n

    natemccurdy

    09/23/2022, 12:52 AM
    Copy code
    let(:pre_condition) { 'user { "nate": }' }
  • n

    n3snah

    09/23/2022, 12:53 AM
    thanks, I did see this but I didn't think this would work as I have a manifest with mixed OS and I need this to be only on Windows.
  • n

    n3snah

    09/23/2022, 1:13 AM
    thanks @natemccurdy, I tried this and it seemed to be fine.
    👍 1
  • n

    n3snah

    09/23/2022, 1:27 AM
    Could I please get assistance with this?
    expected that the catalogue would contain Package[powershell-yaml] with require set to "Psrepository['PSGallery']" but it is set to Psrepository[PSGallery]{:name=>"PSGallery"}
    I don't understand what this is trying to say and how to fix it. It should be the same. spec file
    Copy code
    it do
              <http://is_expected.to|is_expected.to> contain_package('powershell-yaml').with(
                'ensure' => '0.4.3',
                'provider' => 'windowspowershell',
                'source' => 'PSGallery',
                'require' => "Psrepository['PSGallery']",
              )
            end
    Manifest
    Copy code
    package { 'powershell-yaml':
          ensure   => '0.4.3',
          provider => 'windowspowershell',
          source   => 'PSGallery',
          require  => Psrepository['PSGallery']
        }
  • n

    natemccurdy

    09/23/2022, 1:28 AM
    This is in those docs I linked. Check out https://rspec-puppet.com/documentation/classes/#testing-relationships-between-resources
  • n

    natemccurdy

    09/23/2022, 1:29 AM
    You want
    .that_requires('Psrepository[PSGallery]')
    rather than putting
    require
    in the
    with()
    statement.
  • n

    n3snah

    09/23/2022, 1:29 AM
    oh... I always thought they were the same thing?
  • n

    natemccurdy

    09/23/2022, 1:30 AM
    .that_requires()
    is a helper that extracts the name of the resource into a more easily referencable thing.
1...171172173...428Latest