Merge branch 'pr/1043' into devel

reviewable/pr18780/r1
Toshio Kuratomi 9 years ago
commit 620be97320

@ -48,6 +48,12 @@ options:
description:
- The base path where to install the bower packages
required: true
relative_execpath:
description:
- Relative path to bower executable from install path
default: null
required: false
version_added: "2.1"
state:
description:
- The state of the bower package
@ -75,6 +81,10 @@ description: Install packages based on bower.json.
description: Update packages based on bower.json to their latest version.
- bower: path=/app/location state=latest
description: install bower locally and run from there
- npm: path=/app/location name=bower global=no
- bower: path=/app/location relative_execpath=node_modules/.bin
'''
@ -85,6 +95,7 @@ class Bower(object):
self.offline = kwargs['offline']
self.production = kwargs['production']
self.path = kwargs['path']
self.relative_execpath = kwargs['relative_execpath']
self.version = kwargs['version']
if kwargs['version']:
@ -94,7 +105,17 @@ class Bower(object):
def _exec(self, args, run_in_check_mode=False, check_rc=True):
if not self.module.check_mode or (self.module.check_mode and run_in_check_mode):
cmd = ["bower"] + args + ['--config.interactive=false', '--allow-root']
cmd = []
if self.relative_execpath:
cmd.append(os.path.join(self.path, self.relative_execpath, "bower"))
if not os.path.isfile(cmd[-1]):
self.module.fail_json(msg="bower not found at relative path %s" % self.relative_execpath)
else:
cmd.append("bower")
cmd.extend(args)
cmd.extend(['--config.interactive=false', '--allow-root'])
if self.name:
cmd.append(self.name_version)
@ -130,10 +151,9 @@ class Bower(object):
dep_data = data['dependencies'][dep]
if dep_data.get('missing', False):
missing.append(dep)
elif \
'version' in dep_data['pkgMeta'] and \
'update' in dep_data and \
dep_data['pkgMeta']['version'] != dep_data['update']['latest']:
elif ('version' in dep_data['pkgMeta'] and
'update' in dep_data and
dep_data['pkgMeta']['version'] != dep_data['update']['latest']):
outdated.append(dep)
elif dep_data.get('incompatible', False):
outdated.append(dep)
@ -160,7 +180,8 @@ def main():
name=dict(default=None),
offline=dict(default='no', type='bool'),
production=dict(default='no', type='bool'),
path=dict(required=True),
path=dict(required=True, type='path'),
relative_execpath=dict(default=None, required=False, type='path'),
state=dict(default='present', choices=['present', 'absent', 'latest', ]),
version=dict(default=None),
)
@ -172,13 +193,14 @@ def main():
offline = module.params['offline']
production = module.params['production']
path = os.path.expanduser(module.params['path'])
relative_execpath = module.params['relative_execpath']
state = module.params['state']
version = module.params['version']
if state == 'absent' and not name:
module.fail_json(msg='uninstalling a package is only available for named packages')
bower = Bower(module, name=name, offline=offline, production=production, path=path, version=version)
bower = Bower(module, name=name, offline=offline, production=production, path=path, relative_execpath=relative_execpath, version=version)
changed = False
if state == 'present':
@ -201,4 +223,5 @@ def main():
# Import module snippets
from ansible.module_utils.basic import *
main()
if __name__ == '__main__':
main()

Loading…
Cancel
Save