def install_packages(module, xbps_path, state, packages):
 toInstall = []
 for (i, package) in enumerate(packages):
  'If the package is installed and state == present or state == latest\n        and is up-to-date then skip'
  (installed, updated) = query_package(module, xbps_path, package)
  if (installed and ((state == 'present') or ((state == 'latest') and updated))):
   continue
  toInstall.append(package)
 if (len(toInstall) == 0):
  module.exit_json(changed=False, msg='Nothing to Install')
 cmd = ('%s -y %s' % (xbps_path['install'], ' '.join(toInstall)))
 (rc, stdout, stderr) = module.run_command(cmd, check_rc=False)
 if ((rc != 0) and (not ((state == 'latest') and (rc == 17)))):
  module.fail_json(msg=('failed to install %s' % package))
 module.exit_json(changed=True, msg=('installed %s package(s)' % len(toInstall)), packages=toInstall)
 module.exit_json(changed=False, msg='package(s) already installed', packages=[])

def install_packages ( module , xbps_path , state , packages ) : toInstall = [ ] for ( i , package ) in enumerate ( packages ) : ( installed , updated ) = query_package ( module , xbps_path , package ) if ( installed and ( ( state == 'present' ) or ( ( state == 'latest' ) and updated ) ) ) : continue toInstall . append ( package ) if ( len ( toInstall ) == 0 ) : module . exit_json ( changed = False , msg = 'Nothing to Install' ) cmd = ( '%s -y %s' % ( xbps_path [ 'install' ] , ' ' . join ( toInstall ) ) ) ( rc , stdout , stderr ) = module . run_command ( cmd , check_rc = False ) if ( ( rc != 0 ) and ( not ( ( state == 'latest' ) and ( rc == 17 ) ) ) ) : module . fail_json ( msg = ( 'failed to install %s' % package ) ) module . exit_json ( changed = True , msg = ( 'installed %s package(s)' % len ( toInstall ) ) , packages = toInstall ) module . exit_json ( changed = False , msg = 'package(s) already installed' , packages = [ ] )
returns true if package install succeeds .