Skip to content

Commit a95b45c

Browse files
committed
Avoid traceback when using ansible >=2.4
Starting from ansible 2.4 command line options are now received as a list. In ansible >=2.4 it's now technically possible to specify multiple times the '-i' option (even if the documentation say otherwise). This commit merge all host while removing any extra comas.
1 parent 1ff0dc1 commit a95b45c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
CHANGELOG
22
=========
33

4+
# 1.0.2 / 2017-12-11
5+
* [BUGFIX] Avoid failure when using ansible 2.4. See [#27][]
6+
47
# 1.0.1 / 2016-06-06
58
* [BUGFIX] Avoid failure when `res['invocation']` has no `module_name` key. See [#19][]
69

710
# 1.0.0 / 2016-06-02
811
First release, compatible with Ansible v1 & v2
912

1013
<!--- The following link definition list is generated by PimpMyChangelog --->
14+
[#27]: https://github.com/DataDog/ansible-datadog-callback/issues/27
1115
[#19]: https://github.com/DataDog/ansible-datadog-callback/issues/19

datadog_callback.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ def _handle_playbook_on_start(self, playbook_file_name, inventory):
122122
# Set the playbook name from its filename
123123
self._playbook_name, _ = os.path.splitext(
124124
os.path.basename(playbook_file_name))
125-
inventory_name = os.path.basename(os.path.realpath(inventory))
125+
126+
# inventory is a comma separated host list: ["host1,host2","host3,host4,"]
127+
if isinstance(inventory, basestring):
128+
inventory = inventory.split(',')
129+
inventory_name = ','.join([os.path.basename(os.path.realpath(name)) for name in inventory if name])
126130

127131
self.send_playbook_event(
128132
'Ansible playbook "{0}" started by "{1}" against "{2}"'.format(

0 commit comments

Comments
 (0)