puppetlabs/puppetlabs-apt — pull request #320 by leoarnold (2014-06-26 16:08:21+00:00)
Title: Added 'key_options' parameter to defined type apt::source

The `key_options` parameter is the only parameter of `apt::key` which could not be given to `apt::source`. Users who need the `key_options` parameter currently have to compensate like this:

apt::source { 'mysource':
require => Apt::Key['mysource-key'],
[...]
}

apt::key { 'mysource-key':
[...]
key_options => '[...]',
}

This commit allows for intuitive use of GnuPG parameters in the `apt::source` type. See also [Ticket MODULES-434](https://tickets.puppetlabs.com/browse/MODULES-434). While the ticket might be solved another way (see pull request #288), I will still use that particular example to give a demonstration how my commit makes puppet pass a failing test:

Given a network which requires the use of a proxy server, the following test fails:

# from tests/source.pp
apt::source { 'puppetlabs':
location => 'http://apt.puppetlabs.com',
repos => 'main',
key => '4BD6EC30',
key_server => 'pgp.mit.edu',
}

Puppet output:

# puppet apply --verbose tests/source.pp
Error: Execution of '/usr/bin/apt-key adv --keyserver pgp.mit.edu --recv-keys 4BD6EC30' returned 2: Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.dQS1OUWM9X --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyring /etc/apt/trusted.gpg.d//puppetlabs-keyring.gpg --keyserver pgp.mit.edu --recv-keys 4BD6EC30
gpg: requesting key 4BD6EC30 from hkp server pgp.mit.edu
?: pgp.mit.edu: Connection refused
gpgkeys: HTTP fetch error 7: couldn't connect: Connection refused
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
Error: /Stage[main]/Main/Apt::Source[puppetlabs]/Apt::Key[Add key: 4BD6EC30 from Apt::Source puppetlabs]/Apt_key[Add key: 4BD6EC30 from Apt::Source puppetlabs]/ensure: change from absent to present failed: Execution of '/usr/bin/apt-key adv --keyserver pgp.mit.edu --recv-keys 4BD6EC30' returned 2: Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.dQS1OUWM9X --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyring /etc/apt/trusted.gpg.d//puppetlabs-keyring.gpg --keyserver pgp.mit.edu --recv-keys 4BD6EC30
gpg: requesting key 4BD6EC30 from hkp server pgp.mit.edu
?: pgp.mit.edu: Connection refused
gpgkeys: HTTP fetch error 7: couldn't connect: Connection refused
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
Notice: /Stage[main]/Main/Apt::Source[puppetlabs]/Apt::Key[Add key: 4BD6EC30 from Apt::Source puppetlabs]/Anchor[apt_key 4BD6EC30 present]: Dependency Apt_key[Add key: 4BD6EC30 from Apt::Source puppetlabs] has failures: true
Warning: /Stage[main]/Main/Apt::Source[puppetlabs]/Apt::Key[Add key: 4BD6EC30 from Apt::Source puppetlabs]/Anchor[apt_key 4BD6EC30 present]: Skipping because of failed dependencies
Notice: /Stage[main]/Main/Apt::Source[puppetlabs]/File[puppetlabs.list]: Dependency Apt_key[Add key: 4BD6EC30 from Apt::Source puppetlabs] has failures: true
Warning: /Stage[main]/Main/Apt::Source[puppetlabs]/File[puppetlabs.list]: Skipping because of failed dependencies

With this commit, one can use

# modified tests/source.pp
apt::source { 'puppetlabs':
location => 'http://apt.puppetlabs.com',
repos => 'main',
key => '4BD6EC30',
key_server => 'pgp.mit.edu',
key_options => 'http-proxy="http://proxyuser:proxypass@example.org:3128"', # Use your proxy here if necessary
}

resulting in

Notice: /Stage[main]/Main/Apt::Source[puppetlabs]/Apt::Key[Add key: 4BD6EC30 from Apt::Source puppetlabs]/Apt_key[Add key: 4BD6EC30 from Apt::Source puppetlabs]/ensure: created