Skip to content

Commit

Permalink
Merge pull request CentOS-PaaS-SIG#564 from samvarankashyap/ansible2.…
Browse files Browse the repository at this point in the history
…5_fix
  • Loading branch information
paas-bot committed May 1, 2018
2 parents 088f3b2 + c0e2335 commit 5f0b30f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
11 changes: 9 additions & 2 deletions linchpin/ansible_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from contextlib import contextmanager

ansible24 = float(ansible.__version__[0:3]) >= 2.4
ansible_version = float(ansible.__version__[0:3])


# CentOS 6 EPEL provides an alternate Jinja2 package
Expand Down Expand Up @@ -108,6 +109,10 @@ def ansible_runner(playbook_path,
# that onto this method down the road. The verbosity flag would just live
# in options and we could set the defaults.

# module path cannot accept list in ansible 2.3.x versions
if ansible_version <= 2.3:
module_path = ":".join(module_path)

connect_type = 'ssh'
if 'localhost' in inventory_src:
extra_vars["ansible_python_interpreter"] = sys.executable
Expand Down Expand Up @@ -167,8 +172,10 @@ def ansible_runner(playbook_path,
options,
inventory_src=inventory_src,
console=console)

cb = PlaybookCallback(options=options)
if ansible_version >= 2.5:
cb = PlaybookCallback(options=options, ansible_version=ansible_version)
else:
cb = PlaybookCallback(options=options)

if not console:
results = {}
Expand Down
20 changes: 17 additions & 3 deletions linchpin/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@ class PlaybookCallback(CallbackBase):
"""Playbook callback"""


def __init__(self, display=None, options=None):
super(PlaybookCallback, self).__init__(display=display,
options=options)
def __init__(self, display=None, options=None, ansible_version=2.3):

# note the following if else ladder should be restructured after
# linchpin ansible minimum requirements changed until then
# code should be remained unchanged to maintain backward
# compatibility to ansible 2.3.1 version
if ansible_version >= 2.5:
self._load_name = None
super(PlaybookCallback, self).__init__(display=display,
options=options)
elif ansible_version >= 2.4:
super(PlaybookCallback, self).__init__(display=display,
options=options)
else:
# since ansible 2.3.1 version does not support options in
# inside PlaybbookCallback the options are omitted
super(PlaybookCallback, self).__init__(display=display)

self._options = options
self._display.verbosity = options.verbosity
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apache-libcloud>=0.20.1
click
camel
yamlordereddictloader
ansible>=2.3.1,<2.5.0
ansible>=2.3.1
six>=1.10.0
shade>=1.18.0,!=1.21.0
naked
Expand Down

0 comments on commit 5f0b30f

Please sign in to comment.