Ask Your Question
0

How can this become smarter (shorter) ?

asked 2017-11-24 09:12:46 -0500

marcnesium gravatar image

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 ...
(more)
edit retag flag offensive close merge delete

Comments

Maybe you could programmatically construct your $mirror hash. But that doesn't necessarily increase readability. In any case, I'd deduplicate literals into variables: Some URIs occur multiple times. Place that value in a variable instead (provided it's necessarily the same among all occurrences).

Kai Burghardt gravatar imageKai Burghardt ( 2017-11-25 06:51:02 -0500 )edit

You could put all that into hiera.

Red Cricket gravatar imageRed Cricket ( 2017-11-25 21:50:23 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-12-27 17:21:18 -0500

reidmv gravatar image

updated 2017-12-28 12:18:05 -0500

I don't think I actually recommend this, and chances are I'll regret having posted it later. But academically, as an exercise in "it's shorter", this is something interesting you can do with the language.

This assumes it's ok to declare the resources directly, rather than just building a data hash. It uses a language feature called per-expression default attributes.

https://puppet.com/docs/puppet/5.3/lang_resources_advanced.html#per-expression-default-attributes

The big problem with this is to keep it functional, you have to start paying attention to semi-colons. It can become painfully pedantic to do that. I'd only ever consider doing it in circumstances like this one where it's already painful to deal with due to the sheer amount of data and redundancy.

If it's not acceptable to declare the resources, you're stuck doing programatic things to data. That's possible too but looks much more like programming and will maybe involve writing some functions so that the end result is most readable.

https://puppet.com/docs/puppet/5.3/lang_write_functions_in_puppet.html

Aply::Mirror {
  with_udebs => true,
}

aptly::mirror {
  default:
    location      => 'http://de.archive.ubuntu.com/ubuntu',
    key           => ['40976EAF437D05B5','3B4FE6ACC0B21F32'],
    architectures => ['i386','amd64'],
    keyserver     => 'keyserver.ubuntu.com';
  'xenial_main':
    release       => 'xenial',
    repos         => ['main', 'restricted'];
  'xenial_main_updates':
    release       => 'xenial-updates',
    repos         => ['main', 'restricted'];
  'xenial_universe':
    release       => 'xenial',
    repos         => ['universe'];
  'xenial_universe_updates':
    release       => 'xenial-updates',
    repos         => ['universe'];
  'xenial_multiverse':
    release       => 'xenial',
    repos         => ['multiverse'];
  'xenial_multiverse_updates':
    release       => 'xenial-updates',
    repos         => ['multiverse'];
  'xenial_backports':
    release       => 'xenial-backports',
    repos         => ['main','restricted','universe','multiverse'];
  'zesty_backports':
    release       => 'zesty-backports',
    repos         => ['main','restricted','universe','multiverse'];
  'zesty_multiverse_updates':
    release       => 'zesty-updates',
    repos         => ['multiverse'];
  'zesty_multiverse':
    release       => 'zesty',
    repos         => ['multiverse'];
  'zesty_universe_updates':
    release       => 'zesty-updates',
    repos         => ['universe'];
  'zesty_universe':
    release       => 'zesty',
    repos         => ['universe'];
  'zesty_main':
    release       => 'zesty',
    repos         => ['main', 'restricted'];
  'zesty_main_updates':
    release       => 'zesty-updates',
    repos         => ['main', 'restricted'];
}

aptly::mirror {
  default:
    location      => 'http://security.ubuntu.com/ubuntu',
    key           => [ ],
    architectures => ['i386','amd64'],
    keyserver     => 'keyserver.ubuntu.com';
  'xenial_security':
    release       => 'xenial-security',
    repos         => ['main','restricted'];
  'xenial_security':
    release       => 'xenial-security',
    repos         => ['main','restricted'];
  'xenial_security_universe':
    release       => 'xenial-security',
    repos         => ['universe'];
  'xenial_security_multiverse':
    release       => 'xenial-security',
    repos         => ['multiverse'];
  'zesty_security_multiverse':
    release       => 'zesty-security',
    repos         => ['multiverse'];
  'zesty_security_universe':
    release       => 'zesty-security',
    repos         => ['universe'];
  'zesty_security':
    release       => 'zesty-security',
    repos         => ['main','restricted'];
}

aptly::mirror {
  default:
    location      => 'https://dl.yarnpkg.com/debian/',
    key           => ['72ECF46A56B4AD39C907BBB71646B01B86E50310'],
    architectures => ['amd64'],
    keyserver     => 'hkp://p80.pool.sks-keyservers.net:80';
  'xenial_yarn':
    release       => 'stable',
    repos         => ['main'];
  'zesty_yarn':
    release       => 'stable',
    repos         => ['main'];
}

aptly::mirror {
  default:
    location      => 'http://apt.puppetlabs.com/',
    architectures => ['amd64'],
    key           => ['6F6B15509CF8E59E6E469F327F438280EF8D349F'],
    keyserver     => 'hkp://p80.pool.sks-keyservers.net:80',
    repos         => ['PC1'];
  'xenial_puppet':
    release       => 'xenial';
  'zesty_puppet':
    release       => 'zesty';
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2017-11-24 09:12:46 -0500

Seen: 332 times

Last updated: Dec 28 '17