Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible_playbook_python #18530

Merged
merged 3 commits into from
Nov 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Ansible Changes By Release
any user can add back via config options if they don't use those package managers or othewise avoid the errors.
* Blocks can now have a `name` field, to aid in playbook readability.
* default strategy is now configurable via ansible.cfg or environment variable.
* Added 'ansible_playbook_python' which contains 'current python executable', it can be blank in some cases in which Ansible is not invoked via the standard CLI (sys.executable limitation).

###Deprecations:
* Specifying --tags (or --skip-tags) multiple times on the command line
Expand Down
2 changes: 2 additions & 0 deletions docsite/rst/playbooks_variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,8 @@ period, without the rest of the domain.
.. versionadded:: 2.2
``ansible_play_batch`` is available as a list of hostnames that are in scope for the current 'batch' of the play. The batch size is defined by ``serial``, when not set it is equivalent to the whole play (making it the same as ``ansible_play_hosts``).

.. versionadded:: 2.3
``ansible_playbook_python`` is the path to the python executable used to invoke the Ansible command line tool.

These vars may be useful for filling out templates with multiple hostnames or for injecting the list into the rules for a load balancer.

Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/plugins/action/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def _parse_returned_data(self, res):
pass

# remove some KNOWN keys
for hard in ['ansible_rsync_path']:
for hard in ['ansible_rsync_path', 'ansible_playbook_python']:
if hard in fact_keys:
remove_keys.add(hard)

Expand Down
2 changes: 2 additions & 0 deletions lib/ansible/vars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
__metaclass__ = type

import os
import sys

from collections import defaultdict, MutableMapping

Expand Down Expand Up @@ -392,6 +393,7 @@ def _get_magic_variables(self, loader, play, host, task, include_hostvars, inclu

variables = dict()
variables['playbook_dir'] = loader.get_basedir()
variables['ansible_playbook_python'] = sys.executable

if host:
variables['group_names'] = sorted([group.name for group in host.get_groups() if group.name != 'all'])
Expand Down
13 changes: 5 additions & 8 deletions test/units/vars/test_variable_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,11 @@ def test_basic_manager(self):

v = VariableManager()
vars = v.get_vars(loader=fake_loader, use_cache=False)
if 'omit' in vars:
del vars['omit']
if 'vars' in vars:
del vars['vars']
if 'ansible_version' in vars:
del vars['ansible_version']
if 'ansible_check_mode' in vars:
del vars['ansible_check_mode']

#FIXME: not sure why we remove all and only test playbook_dir
for remove in ['omit', 'vars', 'ansible_version', 'ansible_check_mode', 'ansible_playbook_python']:
if remove in vars:
del vars[remove]

self.assertEqual(vars, dict(playbook_dir='.'))

Expand Down