def remotely_remove_file(system_ip, filename): args = "rm -rf %s" % filename a = Ansible() response = a.run_module(host_list=[system_ip], module="command", args=args) try: if response["contacted"][system_ip]["rc"] > 0: return False except: return False finally: del a return True
def remotely_remove_file(system_ip, filename): args = "rm -rf %s" % filename a = Ansible() response = a.run_module(host_list=[system_ip], module="command", args=args) try: if response['contacted'][system_ip]['rc'] > 0: return False except: return False finally: del a return True
def remotely_copy_file(system_ip, orig, dest): args = "cp %s %s" % (orig, dest) a = Ansible() response = a.run_module(host_list=[system_ip], module="command", args=args) try: if response['contacted'][system_ip]['rc'] > 0: return False except: return False finally: del a return True
def remotely_copy_file(system_ip, orig, dest): args = "cp %s %s" % (orig, dest) a = Ansible() response = a.run_module(host_list=[system_ip], module="command", args=args) try: if response["contacted"][system_ip]["rc"] > 0: return False except: return False finally: del a return True
def touch_file(system_ip, filename): args = "touch %s" % filename a = Ansible() response = a.run_module(host_list=[system_ip], module="command", args=args) print response try: if response['contacted'][system_ip]['rc'] > 0: return False except: return False finally: del a return True
def touch_file(system_ip, filename): args = "touch %s" % filename a = Ansible() response = a.run_module(host_list=[system_ip], module="command", args=args) print response try: if response["contacted"][system_ip]["rc"] > 0: return False except: return False finally: del a return True
try: response = ansible.run_module(host_list=[local_ip], module='stat', args="path="+local_file_path) except Exception, exc: api_log.error("Ansible Error: An error occurred while running stat module: %s" % str(exc)) return False, "Ansible Error: An error occurred while running stat module: %s" % str(exc) (success, msg) = ansible_is_valid_response(local_ip, response) if success: if not response['contacted'][local_ip]['stat']['exists']: local_md5 = 0 else: local_md5 = response['contacted'][local_ip]['stat']['md5'] # Get remote file md5 try: response = ansible.run_module(host_list=[remote_ip], module='stat', args="path="+remote_file_path) except Exception, exc: api_log.error("Ansible Error: An error occurred while running stat module: %s" % str(exc)) return False, "Ansible Error: An error occurred while running stat module: %s" % str(exc) (success, msg) = ansible_is_valid_response(remote_ip, response) if success: if not response['contacted'][remote_ip]['stat']['exists']: return (False, "Remote files does not exist") else: remote_md5 = response['contacted'][remote_ip]['stat']['md5'] if local_md5 and remote_md5 and local_md5 == remote_md5: return (False, "Files already in sync") else: try:
def ansible_set_system_certificate(local_ip, cert, priv, ca): """ Set content of a given file name :returns True if the file is properly created, False elsewhere """ # Copy content to file try: command_args = "content=\"{0}\" dest={1} owner=root group=alienvault mode=\"u+rw,g-wx,o-rwx\"".format(cert,'/etc/ssl/private/custom_ui_certificate.crt') response = ansible.run_module(host_list=[local_ip], module='copy', args=command_args, use_sudo=True) except Exception, exc: return False, "Ansible Error: An error occurred while generating certificate file(s): %s" % str(exc) try: command_args = "content=\"{0}\" dest={1} owner=root group=alienvault mode=\"u+rw,g-wx,o-rwx\"".format(priv,'/etc/ssl/private/custom_ui_private.key') response = ansible.run_module(host_list=[local_ip], module='copy', args=command_args, use_sudo=True) except Exception, exc: return False, "Ansible Error: An error occurred while generating private key file(s): %s" % str(exc) try: if ca: command_args = "content=\"{0}\" dest={1} owner=root group=alienvault mode=\"u+rw,g-wx,o-rwx\"".format(ca,'/etc/ssl/private/custom_ui_ca_certificate.crt') response = ansible.run_module(host_list=[local_ip], module='copy', args=command_args, use_sudo=True) except Exception, exc: return False, "Ansible Error: An error occurred while generating CA certificate file(s): %s" % str(exc) return True, "" def ansible_remove_system_certificate(local_ip): """ Set content of a given file name
hex_server_ip = None try: hex_server_id = get_hex_string_from_uuid(server_id) hex_server_ip = get_ip_hex_from_str(server_ip) except Exception, msg: api_log.error(str(msg)) return False, "[ans_add_server] Bad params: %s" % str(msg) cmd = "echo \"INSERT IGNORE INTO alienvault.server (id, name, ip, port, descr) " \ "VALUES (0x%s, '%s', 0x%s, %d, '%s')\" | ossim-db" % (hex_server_id, re.escape(server_name), hex_server_ip, server_port, re.escape(server_descr)) response = ansible.run_module(host_list=[system_ip], module="shell", args=cmd) success, msg = ansible_is_valid_response(system_ip, response) if not success: api_log.error(msg) return False, "Error setting server data on remote server" if response['contacted'][system_ip]['rc'] != 0: api_log.error(response['contacted'][system_ip]['stderr']) return False, "Error setting server data on remote server database" return True, '' def ans_add_server_hierarchy(system_ip, parent_id, child_id):
args="path=" + local_file_path) except Exception, exc: return False, "Ansible Error: An error occurred while running stat module: %s" % str( exc) (success, msg) = ansible_is_valid_response(local_ip, response) if success: if not response['contacted'][local_ip]['stat']['exists']: local_md5 = 0 else: local_md5 = response['contacted'][local_ip]['stat']['md5'] # Get remote file md5 try: response = ansible.run_module(host_list=[remote_ip], module='stat', args="path=" + remote_file_path) except Exception, exc: return False, "Ansible Error: An error occurred while running stat module: %s" % str( exc) (success, msg) = ansible_is_valid_response(remote_ip, response) if success: if not response['contacted'][remote_ip]['stat']['exists']: return (False, "Remote files does not exist") else: remote_md5 = response['contacted'][remote_ip]['stat']['md5'] if local_md5 and remote_md5 and local_md5 == remote_md5: return (False, "Files already in sync") else:
try: command_args = "content=\"{0}\" dest={1} owner=root group=alienvault mode=\"u+rw,g-wx,o-rwx\"".format( cert, '/etc/ssl/private/custom_ui_certificate.crt') response = ansible.run_module(host_list=[local_ip], module='copy', args=command_args, use_sudo=True) except Exception, exc: return False, "Ansible Error: An error occurred while generating certificate file(s): %s" % str( exc) try: command_args = "content=\"{0}\" dest={1} owner=root group=alienvault mode=\"u+rw,g-wx,o-rwx\"".format( priv, '/etc/ssl/private/custom_ui_private.key') response = ansible.run_module(host_list=[local_ip], module='copy', args=command_args, use_sudo=True) except Exception, exc: return False, "Ansible Error: An error occurred while generating private key file(s): %s" % str( exc) try: if ca: command_args = "content=\"{0}\" dest={1} owner=root group=alienvault mode=\"u+rw,g-wx,o-rwx\"".format( ca, '/etc/ssl/private/custom_ui_ca_certificate.crt') response = ansible.run_module(host_list=[local_ip], module='copy', args=command_args, use_sudo=True) except Exception, exc: return False, "Ansible Error: An error occurred while generating CA certificate file(s): %s" % str(