def ansible_deployment( instance_ip, username, instance_id, playbooks_dir, limit_playbooks=[], limit_hosts={}, extra_vars={}, raise_exception=True): """ Use service.ansible to deploy to an instance. """ if not check_ansible(): return [] logger = create_instance_logger( deploy_logger, instance_ip, username, instance_id) hostname = build_host_name(instance_id, instance_ip) configure_ansible() if not limit_hosts: limit_hosts = {"hostname": hostname, "ip": instance_ip} host_file = settings.ANSIBLE_HOST_FILE identity = Identity.find_instance(instance_id) if identity: time_zone = identity.provider.timezone extra_vars.update({ "TIMEZONE": time_zone, }) extra_vars.update({ "ATMOUSERNAME": username, }) pbs = execute_playbooks( playbooks_dir, host_file, extra_vars, limit_hosts, logger=logger, limit_playbooks=limit_playbooks) if raise_exception: raise_playbook_errors(pbs, instance_ip, hostname) return pbs
def ansible_deployment( instance_ip, username, instance_id, playbooks_dir, limit_playbooks=[], limit_hosts={}, extra_vars={}, raise_exception=True, debug=False, **runner_opts): """ Use service.ansible to deploy to an instance. """ if not check_ansible(): return [] # Expecting to be path-relative to the playbook path, so use basename if type(limit_playbooks) == str: limit_playbooks = limit_playbooks.split(",") if type(limit_playbooks) != list: raise Exception("Invalid 'limit_playbooks' argument (%s). Expected List" % limit_playbooks) limit_playbooks = [os.path.basename(filepath) for filepath in limit_playbooks] logger = create_instance_logger( deploy_logger, instance_ip, username, instance_id) hostname = build_host_name(instance_id, instance_ip) configure_ansible(debug=debug) if debug: runner_opts['verbosity'] = 4 if not limit_hosts: if hostname: limit_hosts = hostname else: limit_hosts = instance_ip host_file = settings.ANSIBLE_HOST_FILE identity = Identity.find_instance(instance_id) if identity: time_zone = identity.provider.timezone extra_vars.update({ "TIMEZONE": time_zone, }) shared_users = list(AtmosphereUser.users_for_instance(instance_id).values_list('username', flat=True)) if not shared_users: shared_users = [username] if username not in shared_users: shared_users.append(username) extra_vars.update({ "SHARED_USERS": shared_users, }) extra_vars.update({ "ATMOUSERNAME": username, }) pbs = execute_playbooks( playbooks_dir, host_file, extra_vars, limit_hosts, logger=logger, limit_playbooks=limit_playbooks, **runner_opts) if raise_exception: raise_playbook_errors(pbs, instance_id, instance_ip, hostname) return pbs
def ansible_deployment(instance_ip, username, instance_id, playbooks_dir, limit_playbooks=[], limit_hosts={}, extra_vars={}, raise_exception=True, **runner_opts): """ Use service.ansible to deploy to an instance. """ if not check_ansible(): return [] # Expecting to be path-relative to the playbook path, so use basename limit_playbooks = [ os.path.basename(filepath) for filepath in limit_playbooks ] logger = create_instance_logger(deploy_logger, instance_ip, username, instance_id) hostname = build_host_name(instance_id, instance_ip) configure_ansible() if not limit_hosts: if hostname: limit_hosts = hostname else: limit_hosts = instance_ip host_file = settings.ANSIBLE_HOST_FILE identity = Identity.find_instance(instance_id) if identity: time_zone = identity.provider.timezone extra_vars.update({ "TIMEZONE": time_zone, }) extra_vars.update({ "ATMOUSERNAME": username, }) pbs = execute_playbooks(playbooks_dir, host_file, extra_vars, limit_hosts, logger=logger, limit_playbooks=limit_playbooks, **runner_opts) if raise_exception: raise_playbook_errors(pbs, instance_ip, hostname) return pbs
def ansible_deployment(instance_ip, username, instance_id, playbooks_dir, limit_playbooks=[], limit_hosts={}, extra_vars={}, raise_exception=True, debug=False, **runner_opts): """ Use service.ansible to deploy to an instance. """ if not check_ansible(): return [] # Expecting to be path-relative to the playbook path, so use basename if type(limit_playbooks) == str: limit_playbooks = limit_playbooks.split(",") if type(limit_playbooks) != list: raise Exception( "Invalid 'limit_playbooks' argument (%s). Expected List" % limit_playbooks) limit_playbooks = [ os.path.basename(filepath) for filepath in limit_playbooks ] logger = create_instance_logger(deploy_logger, instance_ip, username, instance_id) hostname = build_host_name(instance_id, instance_ip) configure_ansible(debug=debug) if debug: runner_opts['verbosity'] = 4 if not limit_hosts: if hostname: limit_hosts = hostname else: limit_hosts = instance_ip host_file = settings.ANSIBLE_HOST_FILE identity = Identity.find_instance(instance_id) if identity: time_zone = identity.provider.timezone extra_vars.update({ "TIMEZONE": time_zone, }) shared_users = list( AtmosphereUser.users_for_instance(instance_id).values_list('username', flat=True)) if not shared_users: shared_users = [username] if username not in shared_users: shared_users.append(username) extra_vars.update({ "SHARED_USERS": shared_users, }) extra_vars.update({ "ATMOUSERNAME": username, }) pbs = execute_playbooks(playbooks_dir, host_file, extra_vars, limit_hosts, logger=logger, limit_playbooks=limit_playbooks, **runner_opts) if raise_exception: raise_playbook_errors(pbs, instance_id, instance_ip, hostname) return pbs