Skip to content

Commit

Permalink
Clean up pycache dirs
Browse files Browse the repository at this point in the history
Move files to collection structure

Hooked up collection path

Remove stuff from tests

Cleanup collection transition work, remove extra module

fix ad hoc commands

Set python path
  • Loading branch information
AlanCoding committed Aug 21, 2020
1 parent 024e74a commit 351d76b
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 69 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ test/integration/containerized/priv_data/artifacts/
*,cover
.venv
.env
/test/integration/artifacts/
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ clean:
rm -rf rpm-build
rm -rf deb-build
find . -type f -regex ".*\py[co]$$" -delete
find . -type d -name "__pycache__" -delete

dist:
poetry build
Expand Down
25 changes: 0 additions & 25 deletions ansible_runner/display_callback/__init__.py

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,10 @@
- Set as stdout in config
'''

# Python
import os # noqa
import sys # noqa

# Add awx/lib to sys.path.
awx_lib_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
if awx_lib_path not in sys.path:
sys.path.insert(0, awx_lib_path)

# Tower Display Callback
from display_callback import AWXDefaultCallbackModule # noqa
# AWX Display Callback
from ..module_utils import cleanup # noqa (registers control persistent cleanup)
from ..module_utils import display # noqa (wraps ansible.display.Display methods)
from ..module_utils.module import AWXDefaultCallbackModule # noqa


# In order to be recognized correctly, self.__class__.__name__ needs to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,10 @@
- Set as stdout in config
'''

# Python
import os # noqa
import sys # noqa

# Add awx/lib to sys.path.
awx_lib_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
if awx_lib_path not in sys.path:
sys.path.insert(0, awx_lib_path)

# Tower Display Callback
from display_callback import AWXMinimalCallbackModule # noqa
# AWX Display Callback
from ..module_utils import cleanup # noqa (registers control persistent cleanup)
from ..module_utils import display # noqa (wraps ansible.display.Display methods)
from ..module_utils.module import AWXMinimalCallbackModule # noqa


# In order to be recognized correctly, self.__class__.__name__ needs to
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,12 @@ def v2_runner_on_start(self, host, task):

class AWXDefaultCallbackModule(BaseCallbackModule, DefaultCallbackModule):

CALLBACK_NAME = 'awx_display'
CALLBACK_NAME = 'runner.wrapper.awx_display'


class AWXMinimalCallbackModule(BaseCallbackModule, MinimalCallbackModule):

CALLBACK_NAME = 'minimal'
CALLBACK_NAME = 'runner.wrapper.minimal'

def v2_playbook_on_play_start(self, play):
pass
Expand Down
24 changes: 11 additions & 13 deletions ansible_runner/runner_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@ def prepare(self):
It's also responsible for wrapping the command with the proper ssh agent invocation
and setting early ANSIBLE_ environment variables.
"""
# ansible_path = find_executable('ansible')
# if ansible_path is None or not os.access(ansible_path, os.X_OK):
# raise ConfigurationError("Ansible not found. Make sure that it is installed.")
if self.private_data_dir is None:
raise ConfigurationError("Runner Base Directory is not defined")
if self.module and self.playbook:
Expand Down Expand Up @@ -207,21 +204,22 @@ def prepare(self):
open_fifo_write(self.ssh_key_path, self.ssh_key_data)
self.command = self.wrap_args_with_ssh_agent(self.command, self.ssh_key_path)

# Use local callback directory
callback_dir = self.env.get('AWX_LIB_DIRECTORY', os.getenv('AWX_LIB_DIRECTORY'))
# Use local collection directory
collection_dir = self.env.get('AWX_LIB_DIRECTORY', os.getenv('AWX_LIB_DIRECTORY'))
if self.containerized:
callback_dir = '/usr/lib/python3.6/site-packages/ansible_runner/callbacks'
elif callback_dir is None:
callback_dir = os.path.join(os.path.split(os.path.abspath(__file__))[0],
"callbacks")
collection_dir = '/usr/lib/python3.6/site-packages/ansible_runner/lib'
elif collection_dir is None:
runner_root = os.path.split(os.path.abspath(__file__))[0]
collection_dir = os.path.join(runner_root, 'lib')
python_path = self.env.get('PYTHONPATH', os.getenv('PYTHONPATH', ''))
if python_path and not python_path.endswith(':'):
python_path += ':'
self.env['ANSIBLE_CALLBACK_PLUGINS'] = ':'.join(filter(None,(self.env.get('ANSIBLE_CALLBACK_PLUGINS'), callback_dir)))
self.env['ANSIBLE_COLLECTIONS_PATH'] = ':'.join(filter(None,(self.env.get('ANSIBLE_COLLECTIONS_PATHS'), collection_dir)))

if 'AD_HOC_COMMAND_ID' in self.env:
self.env['ANSIBLE_STDOUT_CALLBACK'] = 'minimal'
self.env['ANSIBLE_STDOUT_CALLBACK'] = 'runner.wrapper.minimal'
else:
self.env['ANSIBLE_STDOUT_CALLBACK'] = 'awx_display'
self.env['ANSIBLE_STDOUT_CALLBACK'] = 'runner.wrapper.awx_display'
self.env['ANSIBLE_RETRY_FILES_ENABLED'] = 'False'
if 'ANSIBLE_HOST_KEY_CHECKING' not in self.env:
self.env['ANSIBLE_HOST_KEY_CHECKING'] = 'False'
Expand Down Expand Up @@ -249,7 +247,7 @@ def prepare(self):
self.env['CGROUP_WRITE_FILES'] = 'True'
self.env['CGROUP_DISPLAY_RECAP'] = 'False'

self.env['PYTHONPATH'] = python_path + callback_dir
self.env['PYTHONPATH'] = python_path + collection_dir
if self.roles_path:
self.env['ANSIBLE_ROLES_PATH'] = ':'.join(self.roles_path)

Expand Down
8 changes: 1 addition & 7 deletions test/unit/test_runner_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,12 @@ def test_prepare():
assert not hasattr(rc, 'ssh_key_path')
assert not hasattr(rc, 'command')

assert rc.env['ANSIBLE_STDOUT_CALLBACK'] == 'awx_display'
assert rc.env['ANSIBLE_STDOUT_CALLBACK'] == 'runner.wrapper.awx_display'
assert rc.env['ANSIBLE_RETRY_FILES_ENABLED'] == 'False'
assert rc.env['ANSIBLE_HOST_KEY_CHECKING'] == 'False'
assert rc.env['AWX_ISOLATED_DATA_DIR'] == '/'
assert rc.env['PYTHONPATH'] == '/python_path_via_environ:/awx_lib_directory_via_environ', \
"PYTHONPATH is the union of the env PYTHONPATH and AWX_LIB_DIRECTORY"

del rc.env['PYTHONPATH']
os.environ['PYTHONPATH'] = "/foo/bar/python_path_via_environ"
rc.prepare()
assert rc.env['PYTHONPATH'] == "/foo/bar/python_path_via_environ:/awx_lib_directory_via_environ", \
"PYTHONPATH is the union of the explicit env['PYTHONPATH'] override and AWX_LIB_DIRECTORY"


@patch('ansible_runner.runner_config.open_fifo_write')
Expand Down

0 comments on commit 351d76b

Please sign in to comment.