Add an accept_licenses option to pkg5 module

This accepts any software licences required by the package.
This commit is contained in:
Peter Oliver 2015-04-04 19:27:37 +01:00
parent 4048de9c1e
commit 9d720f52c8

View file

@ -39,6 +39,13 @@ options:
required: false required: false
default: present default: present
choices: [ present, latest, absent ] choices: [ present, latest, absent ]
accept_licenses:
description:
- Accept any licences.
required: false
default: false
choices: [ true, false ]
aliases: [ accept_licences, accept ]
''' '''
EXAMPLES = ''' EXAMPLES = '''
# Install Vim: # Install Vim:
@ -70,6 +77,11 @@ def main():
'removed', 'removed',
] ]
), ),
accept_licenses=dict(
choices=BOOLEANS,
default=False
aliases=['accept_licences', 'accept']
),
) )
) )
@ -89,14 +101,14 @@ def main():
packages.append(fragment) packages.append(fragment)
if params['state'] in ['present', 'installed']: if params['state'] in ['present', 'installed']:
ensure(module, 'present', packages) ensure(module, 'present', packages, params)
elif params['state'] in ['latest']: elif params['state'] in ['latest']:
ensure(module, 'latest', packages) ensure(module, 'latest', packages, params)
elif params['state'] in ['absent', 'uninstalled', 'removed']: elif params['state'] in ['absent', 'uninstalled', 'removed']:
ensure(module, 'absent', packages) ensure(module, 'absent', packages, params)
def ensure(module, state, packages): def ensure(module, state, packages, params):
response = { response = {
'results': [], 'results': [],
'msg': '', 'msg': '',
@ -119,7 +131,13 @@ def ensure(module, state, packages):
to_modify = filter(behaviour[state]['filter'], packages) to_modify = filter(behaviour[state]['filter'], packages)
if to_modify: if to_modify:
rc, out, err = module.run_command( rc, out, err = module.run_command(
['pkg', behaviour[state]['subcommand'], '-q', '--'] + to_modify [
'pkg', behaviour[state]['subcommand']
]
+ (['--accept'] if params['accept_licenses'] else [])
+ [
'-q', '--'
] + to_modify
) )
response['rc'] = rc response['rc'] = rc
response['results'].append(out) response['results'].append(out)