def receive(organization=None, user=None, team=None, credential_type=None, credential=None, notification_template=None, inventory_script=None, inventory=None, project=None, job_template=None, workflow=None, all=None): """Export assets from Tower. 'tower receive' exports one or more assets from a Tower instance For all of the possible assets types the TEXT can either be the assets name (or username for the case of a user) or the keyword all. Specifying all will export all of the assets of that type. """ from tower_cli.cli.transfer.receive import Receiver receiver = Receiver() assets_to_export = {} for asset_type in SEND_ORDER: assets_to_export[asset_type] = locals()[asset_type] receiver.receive(all=all, asset_input=assets_to_export)
def main(): argument_spec = dict( all=dict(type='bool', default=False), credential=dict(type='list', default=[], elements='str'), credential_type=dict(type='list', default=[], elements='str'), inventory=dict(type='list', default=[], elements='str'), inventory_script=dict(type='list', default=[], elements='str'), job_template=dict(type='list', default=[], elements='str'), notification_template=dict(type='list', default=[], elements='str'), organization=dict(type='list', default=[], elements='str'), project=dict(type='list', default=[], elements='str'), team=dict(type='list', default=[], elements='str'), user=dict(type='list', default=[], elements='str'), workflow=dict(type='list', default=[], elements='str'), ) module = TowerLegacyModule(argument_spec=argument_spec, supports_check_mode=False) module.deprecate( msg= "This module is deprecated and will be replaced by the AWX CLI export command.", version="awx.awx:14.0.0") if not HAS_TOWER_CLI: module.fail_json(msg='ansible-tower-cli required for this module') if not TOWER_CLI_HAS_EXPORT: module.fail_json( msg='ansible-tower-cli version does not support export') export_all = module.params.get('all') assets_to_export = {} for asset_type in SEND_ORDER: assets_to_export[asset_type] = module.params.get(asset_type) result = dict( assets=None, changed=False, message='', ) tower_auth = tower_auth_config(module) with settings.runtime_values(**tower_auth): try: receiver = Receiver() result['assets'] = receiver.export_assets( all=export_all, asset_input=assets_to_export) module.exit_json(**result) except TowerCLIError as e: result['message'] = e.message module.fail_json(msg='Receive Failed', **result)
def tower_receive(asset_type, asset_name): """ Receive assets from Tower Arguments: asset_type -- asset type, eg. job_template asset_name Returns: assets objects """ if asset_type not in ASSET_TYPES: raise Error(f"Unsupported asset type '{asset_type}'!") to_export = {asset_type: [asset_name]} receiver = Receiver() assets = receiver.export_assets(all=False, asset_input=to_export) # recursively convert OrderedDict to Dict # source: https://stackoverflow.com/a/27373073 return json.loads(json.dumps(assets))