runner: added raising exceptions
Change-Id: I8660ea74f6d72969c32ec75dfee08c48de0d1c12
This commit is contained in:
@@ -18,6 +18,8 @@ import os
|
||||
|
||||
import ansible_runner
|
||||
|
||||
from kue import exceptions
|
||||
|
||||
|
||||
class Cluster(object):
|
||||
def __init__(self, config):
|
||||
@@ -29,8 +31,13 @@ class Cluster(object):
|
||||
|
||||
try:
|
||||
shutil.copytree(playbooks_dir, '%s/project' % private_data_dir)
|
||||
ansible_runner.run(private_data_dir=private_data_dir,
|
||||
inventory=self.config.inventory,
|
||||
playbook='site.yaml')
|
||||
result = ansible_runner.run(private_data_dir=private_data_dir,
|
||||
inventory=self.config.inventory,
|
||||
settings={'pexpect_use_poll': False},
|
||||
playbook='site.yaml')
|
||||
if result.status == 'failed' or \
|
||||
(result.stats and result.stats.get('failures', [])):
|
||||
message = ' '.join(result.stdout)
|
||||
raise exceptions.AnsibleRunnerException(message)
|
||||
finally:
|
||||
shutil.rmtree(private_data_dir, ignore_errors=True)
|
||||
|
||||
18
kue/exceptions.py
Normal file
18
kue/exceptions.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Copyright 2019 VEXXHOST, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
class AnsibleRunnerException(Exception):
|
||||
def __init__(self, message):
|
||||
super(AnsibleRunnerException, self).__init__(message)
|
||||
Reference in New Issue
Block a user