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

    vchepkov

    05/12/2022, 5:47 PM
    you should stop 🙂
  • b

    Brian Schonecker

    05/12/2022, 5:47 PM
    Why is that?
  • b

    Brian Schonecker

    05/12/2022, 5:48 PM
    I've had great success using create_resources.
  • b

    Brian Schonecker

    05/12/2022, 5:48 PM
    ...except for the resource ordering. 🙂
  • v

    vchepkov

    05/12/2022, 5:49 PM
    It's an outdated construct from the time when iterations were not present in puppet
    Copy code
    class profile::users {
      Hash $list = {},
    } {
      $list.each | $user, $attributes| {
        user { $user:
          * => $attributes,
          before => Class['my_class'],
        }
    }
  • v

    vchepkov

    05/12/2022, 5:50 PM
    It's an outdated construct from the time when iterations were not present in puppet
    Copy code
    class profile::users {
      Hash $list = {},
    } {
      $list.each | $user, $attributes| {
        user { $user:
          * => $attributes,
          before => Class['my_class'],
        }
    }
  • b

    Brian Schonecker

    05/12/2022, 5:50 PM
    Thanks for the tip. I'll look into iterations as you suggest. I've been out of the Puppet scene for about five years and a lot has changed.
  • b

    Brian Schonecker

    05/12/2022, 5:52 PM
    yeah, that looks a lot better. Thank you.
  • d

    dmnfortytwo

    05/12/2022, 5:58 PM
    @vchepkov could you please share any docs that says that create_resources() is outdated? I mean official docs.
  • v

    vchepkov

    05/12/2022, 5:59 PM
    https://puppet.com/docs/puppet/6/function.html#create-resources The use is discouraged :)
  • d

    dmnfortytwo

    05/12/2022, 6:02 PM
    Don't think that 'use selectively' means "don't use as it's outdated'"
    🤷 1
  • l

    Lumiere

    05/12/2022, 6:28 PM
    For create_resources, there's been some discussion on the slack about why it's discouraged, and the gist of it was that it isn't the equivalent of actually looping over the resources and creating them in all cases, so that person strongly recommended you do iteration+individual resources
    💯 1
  • l

    Lumiere

    05/12/2022, 6:29 PM
    if nothing else, create_resources is very opaque to the next person who has to read through it all, the iterative version has a thing that looks like a resource.
  • t

    todd.seidenberg

    05/12/2022, 7:53 PM
    I have the following resource:
  • t

    todd.seidenberg

    05/12/2022, 7:55 PM
    Copy code
    @user { $this_user:
              ensure           => present,
              password         => "${engops_users[$this_user][password]}",
              gid              => "${engops_users[$this_user][gid]}",
              uid              => "${engops_users[$this_user][uid]}",
              comment          => "${engops_users[$this_user][comment]}",
              managehome       => true,
              groups           => "${engops_users[$this_user][groups]}",
              shell            => '/bin/bash',
              password_max_age => '-1',
            }
    and I have the following hiera
    Copy code
    joeuser:
        comment: "joe user"
        uid: "4001"
        gid: "4001"
        groups:
          - 'yubikeyusers'
          - 'wcis'
          - 'wheel'
        password: "SHA"
  • t

    todd.seidenberg

    05/12/2022, 7:56 PM
    But I'm being told:
  • b

    bastelfreak

    05/12/2022, 7:56 PM
    oh no a virtual resource
  • t

    todd.seidenberg

    05/12/2022, 7:56 PM
    Copy code
    Group names must be provided as an array, not a comma-separated list.
  • t

    todd.seidenberg

    05/12/2022, 7:57 PM
    The groups are being specified as an array already.
  • t

    todd.seidenberg

    05/12/2022, 7:57 PM
    so I'm not sure why it doesn't like them.
  • v

    vchepkov

    05/12/2022, 7:57 PM
    "" removes array
  • v

    vchepkov

    05/12/2022, 7:58 PM
    try without quotes
  • t

    todd.seidenberg

    05/12/2022, 7:58 PM
    meaning the
    "${engops_users[$this_user][groups]}"
  • t

    todd.seidenberg

    05/12/2022, 7:58 PM
    should be without quotes?
  • v

    vchepkov

    05/12/2022, 7:58 PM
    if you don't want a string :)
  • t

    tias

    05/12/2022, 7:58 PM
    Same for your other attributes btw 😉
  • v

    vchepkov

    05/12/2022, 7:59 PM
    but I would not do it like that
  • b

    bastelfreak

    05/12/2022, 7:59 PM
    most of those quotes are useless. drop them and directly reference the variable
  • v

    vchepkov

    05/12/2022, 7:59 PM
    https://puppetcommunity.slack.com/archives/C0W298S9G/p1652377751924469
  • v

    vchepkov

    05/12/2022, 8:00 PM
    same deal, no need to duplicate attributes and support just a limited set of the resource's attributes
1...363738...428Latest