Add error handling for ansible_playbook handler

This commit is contained in:
Dmitry Shulyak 2015-07-02 09:17:09 +03:00
parent f7c7d1ad95
commit b6cddda994
5 changed files with 25 additions and 8 deletions

View File

@ -1,4 +1,9 @@
- hosts: '*'
- hosts: localhost
sudo: yes
vars:
var1: 'playbook'
roles:
- { role: "test_role" }
- { role: "test_role" }
tasks:
- debug: msg="VAR1 value is {{var1}}"
- fail: msg='just test failure'

View File

@ -4,7 +4,7 @@ version: 0.0.1
input:
var1:
type: str!
value: some_value
value: meta
uuid:
type: str!
value: 'aa1das1231'

View File

@ -1,4 +1,6 @@
- hosts: '*'
sudo: yes
vars:
default1: playbook
tasks:
- debug: "my message"
- debug: msg="my message {{default1}}"

View File

@ -11,3 +11,6 @@ input:
ssh_key:
type: str!
value:
default1:
type: str!
value: meta

View File

@ -8,6 +8,7 @@ from ansible import callbacks
import ansible.constants as C
from solar.core.handlers import base
from solar import errors
class AnsiblePlaybook(base.BaseHandler):
@ -24,16 +25,16 @@ class AnsiblePlaybook(base.BaseHandler):
remote_user = variables.get('ssh_user') or C.DEFAULT_REMOTE_USER
private_key_file = variables.get('ssh_key') or C.DEFAULT_PRIVATE_KEY_FILE
if variables.get('ip'):
host_list = [variables['ip']]
host = variables['ip']
transport = C.DEFAULT_TRANSPORT
else:
host_list = ['localhost']
host = 'localhost'
transport = 'local'
play = PlayBook(
playbook=action_file,
remote_user=remote_user,
host_list = host_list,
host_list = [host],
private_key_file=private_key_file,
extra_vars=variables,
callbacks=playbook_cb,
@ -41,4 +42,10 @@ class AnsiblePlaybook(base.BaseHandler):
stats=stats,
transport=transport)
return play.run()
play.run()
summary = stats.summarize(host)
if summary.get('unreachable') or summary.get('failures'):
raise errors.SolarError(
'Ansible playbook %s failed with next summary %s',
action_file, summary)