How can this become smarter (shorter) ?

28 views
Skip to first unread message

matt...@gmail.com

unread,
Nov 24, 2017, 10:09:05 AM11/24/17
to Puppet Users
Hi, this looks like lots of code and could be more efficient (Zesty & Xenial )?

Thanks for your support !
    

   $mirrors         = {
        'xenial_main' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'xenial',
          repos         => ['main', 'restricted'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'xenial_main_updates' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'xenial-updates',
          repos         => ['main', 'restricted'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'xenial_universe' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'xenial',
          repos         => ['universe'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'xenial_universe_updates' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'xenial-updates',
          repos         => ['universe'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'xenial_multiverse' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'xenial',
          repos         => ['multiverse'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'xenial_multiverse_updates' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'xenial-updates',
          repos         => ['multiverse'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'xenial_backports' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'xenial-backports',
          repos         => ['main','restricted','universe','multiverse'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'xenial_security' => {
          location      => 'http://security.ubuntu.com/ubuntu',
          release       => 'xenial-security',
          repos         => ['main','restricted'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'xenial_security' => {
          location      => 'http://security.ubuntu.com/ubuntu',
          release       => 'xenial-security',
          repos         => ['main','restricted'],
          architectures => ['i386','amd64'],
          key           => [],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'xenial_security_universe' => {
          location      => 'http://security.ubuntu.com/ubuntu',
          release       => 'xenial-security',
          repos         => ['universe'],
          architectures => ['i386','amd64'],
          key           => [],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'xenial_security_multiverse' => {
          location      => 'http://security.ubuntu.com/ubuntu',
          release       => 'xenial-security',
          repos         => ['multiverse'],
          architectures => ['i386','amd64'],
          key           => [],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'xenial_yarn'   => {
          location      => 'https://dl.yarnpkg.com/debian/',
          release       => 'stable',
          repos         => ['main'],
          architectures => ['amd64'],
          key           => ['72ECF46A56B4AD39C907BBB71646B01B86E50310'],
          keyserver     => 'hkp://p80.pool.sks-keyservers.net:80',
        },
        'xenial_puppet'   => {
          location      => 'http://apt.puppetlabs.com/',
          release       => 'xenial',
          repos         => ['PC1'],
          architectures => ['amd64'],
          key           => ['6F6B15509CF8E59E6E469F327F438280EF8D349F'],
          keyserver     => 'hkp://p80.pool.sks-keyservers.net:80',
        },
        'zesty_puppet'  => {
          location      => 'http://apt.puppetlabs.com/',
          release       => 'zesty',
          repos         => ['PC1'],
          architectures => ['amd64'],
          key           => ['6F6B15509CF8E59E6E469F327F438280EF8D349F'],
          keyserver     => 'hkp://p80.pool.sks-keyservers.net:80',
        },
        'zesty_yarn'   => {
          location      => 'https://dl.yarnpkg.com/debian/',
          release       => 'stable',
          repos         => ['main'],
          architectures => ['amd64'],
          key           => ['72ECF46A56B4AD39C907BBB71646B01B86E50310'],
          keyserver     => 'hkp://p80.pool.sks-keyservers.net:80',
        },
        'zesty_security_multiverse' => {
          location      => 'http://security.ubuntu.com/ubuntu',
          release       => 'zesty-security',
          repos         => ['multiverse'],
          architectures => ['i386','amd64'],
          key           => [],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'zesty_security_universe' => {
          location      => 'http://security.ubuntu.com/ubuntu',
          release       => 'zesty-security',
          repos         => ['universe'],
          architectures => ['i386','amd64'],
          key           => [],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'zesty_security' => {
          location      => 'http://security.ubuntu.com/ubuntu',
          release       => 'zesty-security',
          repos         => ['main','restricted'],
          architectures => ['i386','amd64'],
          key           => [],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'zesty_security' => {
          location      => 'http://security.ubuntu.com/ubuntu',
          release       => 'zesty-security',
          repos         => ['main','restricted'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'zesty_backports' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'zesty-backports',
          repos         => ['main','restricted','universe','multiverse'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'zesty_multiverse_updates' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'zesty-updates',
          repos         => ['multiverse'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'zesty_multiverse' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'zesty',
          repos         => ['multiverse'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'zesty_universe_updates' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'zesty-updates',
          repos         => ['universe'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'zesty_universe' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'zesty',
          repos         => ['universe'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'zesty_main' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'zesty',
          repos         => ['main', 'restricted'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        },
        'zesty_main_updates' => {
          location      => 'http://de.archive.ubuntu.com/ubuntu',
          release       => 'zesty-updates',
          repos         => ['main', 'restricted'],
          architectures => ['i386','amd64'],
          key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
          keyserver     => 'keyserver.ubuntu.com',
          with_udebs    => true,
        }
      }

Henrik Lindberg

unread,
Nov 24, 2017, 11:30:12 AM11/24/17
to puppet...@googlegroups.com

On 24/11/17 16:09, matt...@gmail.com wrote:
> Hi, this looks like lots of code and could be more efficient (Zesty &
> Xenial )?
>

You have quite a lot of repetition - you can fix that by using
a default section for your resources. It is a bit of work to find
all repeated settings so I am only showing it in principle:

$xenial_defaults = {
release => 'xenial',
repos => ['main', 'restricted'],
with_udebs => true,
key => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
# and so on...
}

$mirrors = {
'xenial_main' => $xenial_defaults + {
# keys that differ or additional keys
},
'xenial_main_updates' => $xenial_defaults + {
'release' => 'xenial-updates',
# keys that differ or additional keys
},
# etc, etc
}

- henrik
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to puppet-users...@googlegroups.com
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/40f88e69-16b8-43b0-8898-5432fdada291%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/40f88e69-16b8-43b0-8898-5432fdada291%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Johan Fleury

unread,
Dec 2, 2017, 9:31:44 AM12/2/17
to puppet...@googlegroups.com
Le vendredi 24 novembre 2017 à 17:29 +0100, Henrik Lindberg a écrit :
> On 24/11/17 16:09, matt...@gmail.com wrote:
> > Hi, this looks like lots of code and could be more efficient (Zesty &
> > Xenial )?
> >
>
> You have quite a lot of repetition - you can fix that by using
> a default section for your resources. It is a bit of work to find
> all repeated settings so I am only showing it in principle:
>

Even better, you could pass the `$xenial_defaults` variable to create_resource:

```
$xenial_defaults = {
release => 'xenial',
repos => ['main', 'restricted'],
with_udebs => true,
key => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
# and so on...
}

$mirrors = {
'xenial_main' => {
# keys that differ or additional keys
},
'xenial_main_updates' => {
'release' => 'xenial-updates',
# keys that differ or additional keys
},
# etc, etc
}

create_resources('::apt::source', $mirrors, $xenial_defaults)
```

--
Johan Fleury
PGP Key ID : 0x5D404386805E56E6
signature.asc
Reply all
Reply to author
Forward
0 new messages