Estou escrevendo um módulo personalizado para criar um espelho local no Ubuntu usando debmirror
. Aqui está o meu código:
'''
Build a local mirror with debmirror.
'''
import logging
import os
import salt.utils
from salt.exceptions import CommandExecutionError
def created(arch,
section,
server,
release,
in_path,
proto,
out_path,
**kwargs):
'''
'''
__salt__['file.makedirs'](out_path)
if 'gnupghome' in kwargs:
gnupghome = kwargs.pop('gnupghome', None)
__salt__['file.makedirs'](gnupghome)
else:
gnupghome = '/root/.gnupg'
env = { 'GNUPGHOME': gnupghome }
if 'keyid' in kwargs:
keyid = kwargs.pop('keyid', None)
ks = kwargs.pop('keyserver', None)
if not keyid or not ks:
error_str = 'both keyserver and keyid options required.'
raise NameError(error_str)
cmd = 'apt-key export {0}'.format(keyid)
output = __salt__['cmd.run_stdout'](cmd, **kwargs)
imported = output.startswith('-----BEGIN PGP')
if ks:
if not imported:
cmd = ('gpg --no-default-keyring --keyring {0}/trustedkeys.gpg --keyserver {1} --recv-keys {2}')
ret = __salt__['cmd.run_all'](cmd.format(gnupghome, ks, keyid),
**kwargs)
if ret['retcode'] != 0:
raise CommandExecutionError(
'Error: key retrieval failed: {0}'
.format(ret['stdout'])
)
elif 'key_url' in kwargs:
key_url = kwargs['key_url']
cmd = 'wget -q -O- "{0}" | gpg --no-default-keyring --keyring {1}/trustedkeys.gpg --import'.format(key_url, gnupghome)
ret = __salt__['cmd.run_all'](cmd, **kwargs)
if ret['retcode'] != 0:
raise CommandExecutionError(
'Error: key retrieval failed: {0}'.format(ret['stderr'])
)
return __salt__['cmd.run_all']('debmirror -a {0} --no-source -s {1} -h {2} -d {3} -r {4} --progress -e {5} {6}'.format(arch, section, server, release, in_path, proto, out_path), env=env)
Este módulo está funcionando bem ao testar o lacaio:
salt-call debmirror.created /home/mirrorkeyring/ \
i386,amd64 \
main,restricted,universe,multiverse \
ppa.launchpad.net \
precise \
/saltstack/salt/ubuntu \
http \
/saltmirror \
key_url='http://keyserver.ubuntu.com:11371/pks/lookup?op=get&search=0x4759FA960E27C0A6'
Mas eu estou querendo saber isso: como posso definir kwargs
em um arquivo de estado?
{% for package in ('debmirror', 'wget', 'gnupg') %}
{{ package }}:
pkg:
- installed
{% endfor %}
salt-mirror:
module:
- run
- name: debmirror.created
- arch: i386,amd64
- section: main,restricted,universe,multiverse
- release: precise
- server: ppa.launchpad.net
- in_path: /saltstack/salt/ubuntu
- proto: http
- out_path: /saltmirror
- <WHAT SHOULD I PUT HERE?>
- require:
- pkg: debmirror