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 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
import traceback from tempfile import NamedTemporaryFile import api_log from ansiblemethods.ansiblemanager import Ansible, PLAYBOOKS from ansiblemethods.helper import ansible_is_valid_response from apimethods.utils import is_valid_ipv4, set_owner_and_group, set_file_permissions, set_ossec_file_permissions import re import os import json import stat from collections import namedtuple import StringIO # See PEP8 http://legacy.python.org/dev/peps/pep-0008/#global-variable-names # Pylint thinks that a variable at module scope is a constant _ansible = Ansible() # pylint: disable-msg=C0103 def get_ossec_agent_data(host_list=[], args={}): """ Return the ossec agent data @param host_list: List of ip whose data we need """ return _ansible.run_module(host_list, 'ossec_agent', args) def ossec_win_deploy(sensor_ip, agent_name, windows_ip, windows_username, windows_domain, windows_password): """ @param sensor_ip: The sensor IP from where to deploy the ossec agent @agent_name:
import getpass import sys from ansiblemethods.ansiblemanager import Ansible, PLAYBOOKS from db.methods.system import db_get_systems, get_system_id_from_local from ansiblemethods.system.system import ansible_remove_key_from_known_host_file, ansible_add_system from avconfig.ossimsetupconfig import AVOssimSetupConfigHandler ossim_setup = AVOssimSetupConfigHandler() ansible = Ansible() def add_system_with_new_key(local_system_id, remote_system_ip): number_of_tries = 0 status = False while not status and number_of_tries < 3: number_of_tries += 1 msg = 'Please enter root password for {}:\n '.format(remote_system_ip) password = getpass.getpass(msg) status, result = ansible_add_system(local_system_id, remote_system_ip, password) if not status: print(result) return status def confirm(prompt='Confirm', default=False): """ Prompts for yes or no response from the user. Returns True for yes and False for no. Args:
sys.path.append ("/usr/share/alienvault-center/av-libs/avconfig") from avconfig import netinterfaces from ansiblemethods.helper import read_file from ansiblemethods.system.network import get_iface_list, \ get_iface_stats, \ get_conf_network_interfaces, \ set_interfaces_roles from ansiblemethods.server.logger import delete_raw_logs from ansiblemethods.sensor.network import get_sensor_interfaces, \ set_sensor_interfaces from ansiblemethods.ansiblemanager import Ansible AMGR = Ansible() class TestAnsibleMgr (TestCase): """ Root test class for several Ansible methods """ _multiprocess_can_split_ = False # No, I can't split the tests # because each test modified de conf of the system @classmethod def setUpClass(cls): # pylint: disable-msg=C0103 cls.__tempdir = mkdtemp(prefix="nose.temp", dir="/tmp") cls.__confpath = os.path.join( os.path.dirname( os.path.abspath( inspect.getfile(inspect.currentframe()))), "conf")