from ansible import utils from ansible import errors from ansible import module_common import poller import connection from return_data import ReturnData from ansible.callbacks import DefaultRunnerCallbacks, vv HAS_ATFORK=True try: from Crypto.Random import atfork except ImportError: HAS_ATFORK=False dirname = os.path.dirname(__file__) action_plugin_list = utils.import_plugins(os.path.join(dirname, 'action_plugins')) lookup_plugin_list = utils.import_plugins(os.path.join(dirname, 'lookup_plugins')) ################################################ def _executor_hook(job_queue, result_queue): ''' callback used by multiprocessing pool ''' # attempt workaround of https://github.com/newsapps/beeswithmachineguns/issues/17 # this function also not present in CentOS 6 if HAS_ATFORK: atfork() signal.signal(signal.SIGINT, signal.SIG_IGN) while not job_queue.empty(): try:
def __init__(self, playbook=None, host_list=C.DEFAULT_HOST_LIST, module_path=C.DEFAULT_MODULE_PATH, forks=C.DEFAULT_FORKS, timeout=C.DEFAULT_TIMEOUT, remote_user=C.DEFAULT_REMOTE_USER, remote_pass=C.DEFAULT_REMOTE_PASS, sudo_pass=C.DEFAULT_SUDO_PASS, remote_port=C.DEFAULT_REMOTE_PORT, transport=C.DEFAULT_TRANSPORT, private_key_file=C.DEFAULT_PRIVATE_KEY_FILE, callbacks=None, runner_callbacks=None, stats=None, sudo=False, sudo_user=C.DEFAULT_SUDO_USER, extra_vars=None, only_tags=None, subset=C.DEFAULT_SUBSET): """ playbook: path to a playbook file host_list: path to a file like /etc/ansible/hosts module_path: path to ansible modules, like /usr/share/ansible/ forks: desired level of paralellism timeout: connection timeout remote_user: run as this user if not specified in a particular play remote_pass: use this remote password (for all plays) vs using SSH keys sudo_pass: if sudo==True, and a password is required, this is the sudo password remote_port: default remote port to use if not specified with the host or play transport: how to connect to hosts that don't specify a transport (local, paramiko, etc) callbacks output callbacks for the playbook runner_callbacks: more callbacks, this time for the runner API stats: holds aggregrate data about events occuring to each host sudo: if not specified per play, requests all plays use sudo mode """ self.SETUP_CACHE = SETUP_CACHE if playbook is None or callbacks is None or runner_callbacks is None or stats is None: raise Exception('missing required arguments') if extra_vars is None: extra_vars = {} if only_tags is None: only_tags = ['all'] self.module_path = module_path self.forks = forks self.timeout = timeout self.remote_user = remote_user self.remote_pass = remote_pass self.remote_port = remote_port self.transport = transport self.callbacks = callbacks self.runner_callbacks = runner_callbacks self.stats = stats self.sudo = sudo self.sudo_pass = sudo_pass self.sudo_user = sudo_user self.extra_vars = extra_vars self.global_vars = {} self.private_key_file = private_key_file self.only_tags = only_tags self.inventory = ansible.inventory.Inventory(host_list) self.inventory.subset(subset) self.modules_list = utils.get_available_modules(self.module_path) lookup_plugins_dir = os.path.join(plugins_dir, 'lookup_plugins') self.lookup_plugins_list = utils.import_plugins(lookup_plugins_dir) if not self.inventory._is_script: self.global_vars.update(self.inventory.get_group_variables('all')) self.basedir = os.path.dirname(playbook) (self.playbook, self.play_basedirs) = self._load_playbook_from_file(playbook) self.module_path = self.module_path + os.pathsep + os.path.join( self.basedir, "library")
from ansible import utils from ansible import errors from ansible import module_common import poller import connection from return_data import ReturnData from ansible.callbacks import DefaultRunnerCallbacks, vv HAS_ATFORK=True try: from Crypto.Random import atfork except ImportError: HAS_ATFORK=False dirname = os.path.dirname(__file__) action_plugin_list = utils.import_plugins(os.path.join(dirname, 'action_plugins')) ################################################ def _executor_hook(job_queue, result_queue): ''' callback used by multiprocessing pool ''' # attempt workaround of https://github.com/newsapps/beeswithmachineguns/issues/17 # this function also not present in CentOS 6 if HAS_ATFORK: atfork() signal.signal(signal.SIGINT, signal.SIG_IGN) while not job_queue.empty(): try:
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # ################################################ from ansible import utils from ansible.errors import AnsibleError import os.path dirname = os.path.dirname(__file__) modules = utils.import_plugins(os.path.join(dirname, 'connection_plugins')) # rename this module modules['paramiko'] = modules['paramiko_ssh'] del modules['paramiko_ssh'] class Connection(object): ''' Handles abstract connections to remote hosts ''' def __init__(self, runner): self.runner = runner def connect(self, host, port): conn = None transport = self.runner.transport module = modules.get(transport, None)
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # ################################################ from ansible import utils from ansible.errors import AnsibleError import os.path dirname = os.path.dirname(__file__) modules = utils.import_plugins(os.path.join(dirname, 'connection_plugins')) # rename this module modules['paramiko'] = modules['paramiko_ssh'] del modules['paramiko_ssh'] class Connection(object): ''' Handles abstract connections to remote hosts ''' def __init__(self, runner): self.runner = runner def connect(self, host, port=None): conn = None transport = self.runner.transport module = modules.get(transport, None)
from ansible import utils from ansible import errors from ansible import module_common import poller import connection from return_data import ReturnData from ansible.callbacks import DefaultRunnerCallbacks, vv HAS_ATFORK = True try: from Crypto.Random import atfork except ImportError: HAS_ATFORK = False dirname = os.path.dirname(__file__) action_plugins = utils.import_plugins(os.path.join(dirname, 'action_plugins')) ################################################ def _executor_hook(job_queue, result_queue): ''' callback used by multiprocessing pool ''' # attempt workaround of https://github.com/newsapps/beeswithmachineguns/issues/17 # this function also not present in CentOS 6 if HAS_ATFORK: atfork() signal.signal(signal.SIGINT, signal.SIG_IGN) while not job_queue.empty(): try: