diff --git a/README.rst b/README.rst index acbd51f5..359c2d39 100644 --- a/README.rst +++ b/README.rst @@ -29,8 +29,7 @@ Here's how you can get started from scratch with default settings: pip install ansible git+https://github.com/openstack/ara@feature/1.0 # Tell Ansible to use the ARA callback plugin - # "python -m ara.plugins" provides the path to the ARA plugins directory - export ANSIBLE_CALLBACK_PLUGINS="$(python -m ara.plugins)/callback" + export ANSIBLE_CALLBACK_PLUGINS="$(python -m ara.setup.callback_plugins)" # Run your playbook as your normally would ansible-playbook playbook.yml diff --git a/ara/plugins/__init__.py b/ara/plugins/__init__.py deleted file mode 100644 index d6fa9664..00000000 --- a/ara/plugins/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -import os - -LOCATION = os.path.abspath(os.path.dirname(__file__)) diff --git a/ara/setup/README.rst b/ara/setup/README.rst new file mode 100644 index 00000000..c2fabde4 --- /dev/null +++ b/ara/setup/README.rst @@ -0,0 +1,5 @@ +This directory contains scripts meant to help configuring ARA with Ansible. + +For more information, visit the documentation_. + +.. _documentation: http://ara.readthedocs.io/en/latest/configuration.html diff --git a/ara/setup/__init__.py b/ara/setup/__init__.py new file mode 100644 index 00000000..928d8467 --- /dev/null +++ b/ara/setup/__init__.py @@ -0,0 +1,25 @@ +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +import os + +# The path where ARA is installed (parent directory) +path = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) + +plugins = os.path.abspath(os.path.join(path, "plugins")) +action_plugins = os.path.abspath(os.path.join(plugins, "actions")) +callback_plugins = os.path.abspath(os.path.join(plugins, "callbacks")) diff --git a/ara/setup/action_plugins.py b/ara/setup/action_plugins.py new file mode 100644 index 00000000..509b9b6e --- /dev/null +++ b/ara/setup/action_plugins.py @@ -0,0 +1,23 @@ +# Copyright (c) 2019 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +from __future__ import print_function + +from . import action_plugins + +if __name__ == "__main__": + print(action_plugins) diff --git a/ara/setup/ansible.py b/ara/setup/ansible.py new file mode 100644 index 00000000..d2ef26a0 --- /dev/null +++ b/ara/setup/ansible.py @@ -0,0 +1,31 @@ +# Copyright (c) 2019 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +from __future__ import print_function + +from . import action_plugins, callback_plugins + +config = """ +[defaults] +callback_plugins={} +action_plugins={} +""".format( + callback_plugins, action_plugins +) + +if __name__ == "__main__": + print(config.strip()) diff --git a/ara/setup/callback_plugins.py b/ara/setup/callback_plugins.py new file mode 100644 index 00000000..ee7eac00 --- /dev/null +++ b/ara/setup/callback_plugins.py @@ -0,0 +1,23 @@ +# Copyright (c) 2019 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +from __future__ import print_function + +from . import callback_plugins + +if __name__ == "__main__": + print(callback_plugins) diff --git a/ara/setup/env.py b/ara/setup/env.py new file mode 100644 index 00000000..a8a2768c --- /dev/null +++ b/ara/setup/env.py @@ -0,0 +1,48 @@ +# Copyright (c) 2019 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +from __future__ import print_function + +import os +from distutils.sysconfig import get_python_lib + +from . import action_plugins, callback_plugins + +exports = """ +export ANSIBLE_CALLBACK_PLUGINS={} +export ANSIBLE_ACTION_PLUGINS={} +""".format( + callback_plugins, action_plugins +) + +if "VIRTUAL_ENV" in os.environ: + """ PYTHONPATH may be exported when 'ara' module is installed in a + virtualenv and ansible is installed on system python to avoid ansible + failure to find ara module. + """ + # inspired by https://stackoverflow.com/a/122340/99834 + lib = get_python_lib() + if "PYTHONPATH" in os.environ: + python_paths = os.environ["PYTHONPATH"].split(os.pathsep) + else: + python_paths = [] + if lib not in python_paths: + python_paths.append(lib) + exports += "export PYTHONPATH=%s\n" % os.pathsep.join(python_paths) + +if __name__ == "__main__": + print(exports.strip()) diff --git a/ara/plugins/__main__.py b/ara/setup/path.py similarity index 80% rename from ara/plugins/__main__.py rename to ara/setup/path.py index 77cd7c29..21931706 100644 --- a/ara/plugins/__main__.py +++ b/ara/setup/path.py @@ -1,6 +1,6 @@ -# Copyright (c) 2018 Red Hat, Inc. +# Copyright (c) 2019 Red Hat, Inc. # -# This file is part of ARA: Ansible Run Analysis. +# This file is part of ARA Records Ansible. # # ARA is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,7 +15,9 @@ # You should have received a copy of the GNU General Public License # along with ARA. If not, see . -from ara.plugins import LOCATION +from __future__ import print_function + +from . import path if __name__ == "__main__": - print(LOCATION) + print(path) diff --git a/ara/setup/plugins.py b/ara/setup/plugins.py new file mode 100644 index 00000000..afd9688f --- /dev/null +++ b/ara/setup/plugins.py @@ -0,0 +1,23 @@ +# Copyright (c) 2019 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +from __future__ import print_function + +from . import plugins + +if __name__ == "__main__": + print(plugins) diff --git a/roles/ara_tests/tasks/main.yaml b/roles/ara_tests/tasks/main.yaml index 056a6ec4..c922650c 100644 --- a/roles/ara_tests/tasks/main.yaml +++ b/roles/ara_tests/tasks/main.yaml @@ -68,15 +68,15 @@ virtualenv_python: python3 - name: Get ARA plugins directory - command: "{{ ara_tests_virtualenv }}/bin/python -m ara.plugins" - register: ara_plugins + command: "{{ ara_tests_virtualenv }}/bin/python -m ara.setup.plugins" + register: ara_setup_plugins # These aren't in the same task (i.e, with loop) so we can tell individual test # runs apart easily rather than keeping all the output bundled in a single task. # TODO: Add validation for the tests - environment: - ANSIBLE_CALLBACK_PLUGINS: "{{ ara_plugins.stdout }}/callback" - ANSIBLE_ACTION_PLUGINS: "{{ ara_plugins.stdout }}/action" + ANSIBLE_CALLBACK_PLUGINS: "{{ ara_setup_plugins.stdout }}/callback" + ANSIBLE_ACTION_PLUGINS: "{{ ara_setup_plugins.stdout }}/action" ARA_DEBUG: true ARA_LOG_LEVEL: DEBUG ARA_BASE_DIR: "{{ ara_tests_data }}"