From 001ed74273e95a650b80ea5a14a41a1ca94fac7d Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Fri, 24 Nov 2017 14:07:36 -0500 Subject: [PATCH] 1.0 backport: Add helper modules/scripts to know where ARA is The location where ARA is installed is hard to predict because it will depend on the operating system, python2 vs python3 or the usage of virtualenvs, for example. That's why we have this rather convenient snippet: python -c "import os,ara; print(os.path.dirname(ara.__file__))" This snippet is now further reduced to: python -m ara.setup.path But there is also many other variants such as: - python -m ara.setup.path - python -m ara.setup.callback_plugins - python -m ara.setup.action_plugins - python -m ara.setup.library - python -m ara.setup.env - python -m ara.setup.ansible These can also be imported as such: from ara.setup import path from ara.setup import callback_plugins [...] This might be expanded upon later but let's stop at this for now. Change-Id: Ibf1eb495ea0df2f6d8589abeb2220b6e93afdea9 (cherry picked from commit f1e4b5d521b43fb4087391795000b22060d51eb3) --- ara/setup/README.rst | 5 +++ ara/setup/__init__.py | 25 ++++++++++++++ ara/setup/action_plugins.py | 22 ++++++++++++ ara/setup/ansible.py | 29 ++++++++++++++++ ara/setup/callback_plugins.py | 22 ++++++++++++ ara/setup/env.py | 28 +++++++++++++++ ara/setup/library.py | 22 ++++++++++++ ara/setup/path.py | 22 ++++++++++++ ara/tests/unit/test_setup.py | 29 ++++++++++++++++ doc/source/configuration.rst | 64 +++++++++++++++++++++-------------- doc/source/contributing.rst | 2 -- run_tests.sh | 14 ++++++-- 12 files changed, 253 insertions(+), 31 deletions(-) create mode 100644 ara/setup/README.rst create mode 100644 ara/setup/__init__.py create mode 100644 ara/setup/action_plugins.py create mode 100644 ara/setup/ansible.py create mode 100644 ara/setup/callback_plugins.py create mode 100644 ara/setup/env.py create mode 100644 ara/setup/library.py create mode 100644 ara/setup/path.py create mode 100644 ara/tests/unit/test_setup.py 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..8557a6f4 --- /dev/null +++ b/ara/setup/__init__.py @@ -0,0 +1,25 @@ +# Copyright (c) 2017 Red Hat, Inc. +# +# This file is part of ARA: Ansible Run Analysis. +# +# 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__))) + +action_plugins = os.path.abspath(os.path.join(path, 'plugins/actions')) +callback_plugins = os.path.abspath(os.path.join(path, 'plugins/callbacks')) +library = os.path.abspath(os.path.join(path, 'plugins/modules')) diff --git a/ara/setup/action_plugins.py b/ara/setup/action_plugins.py new file mode 100644 index 00000000..b403d56d --- /dev/null +++ b/ara/setup/action_plugins.py @@ -0,0 +1,22 @@ +# Copyright (c) 2017 Red Hat, Inc. +# +# This file is part of ARA: Ansible Run Analysis. +# +# 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..b4bf48ab --- /dev/null +++ b/ara/setup/ansible.py @@ -0,0 +1,29 @@ +# Copyright (c) 2017 Red Hat, Inc. +# +# This file is part of ARA: Ansible Run Analysis. +# +# 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, action_plugins, library + +config = """ +[defaults] +callback_plugins={} +action_plugins={} +library={} +""".format(callback_plugins, action_plugins, library) + +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..297aaf1a --- /dev/null +++ b/ara/setup/callback_plugins.py @@ -0,0 +1,22 @@ +# Copyright (c) 2017 Red Hat, Inc. +# +# This file is part of ARA: Ansible Run Analysis. +# +# 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..66161311 --- /dev/null +++ b/ara/setup/env.py @@ -0,0 +1,28 @@ +# Copyright (c) 2017 Red Hat, Inc. +# +# This file is part of ARA: Ansible Run Analysis. +# +# 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, action_plugins, library + +exports = """ +export ANSIBLE_CALLBACK_PLUGINS={} +export ANSIBLE_ACTION_PLUGINS={} +export ANSIBLE_LIBRARY={} +""".format(callback_plugins, action_plugins, library) + +if __name__ == "__main__": + print(exports.strip()) diff --git a/ara/setup/library.py b/ara/setup/library.py new file mode 100644 index 00000000..85d6fea3 --- /dev/null +++ b/ara/setup/library.py @@ -0,0 +1,22 @@ +# Copyright (c) 2017 Red Hat, Inc. +# +# This file is part of ARA: Ansible Run Analysis. +# +# 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 library + +if __name__ == "__main__": + print(library) diff --git a/ara/setup/path.py b/ara/setup/path.py new file mode 100644 index 00000000..a401e011 --- /dev/null +++ b/ara/setup/path.py @@ -0,0 +1,22 @@ +# Copyright (c) 2017 Red Hat, Inc. +# +# This file is part of ARA: Ansible Run Analysis. +# +# 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 path + +if __name__ == "__main__": + print(path) diff --git a/ara/tests/unit/test_setup.py b/ara/tests/unit/test_setup.py new file mode 100644 index 00000000..58573241 --- /dev/null +++ b/ara/tests/unit/test_setup.py @@ -0,0 +1,29 @@ +# Copyright (c) 2017 Red Hat, Inc. +# +# This file is part of ARA: Ansible Run Analysis. +# +# 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 ara.tests.unit.common import TestAra + + +class TestSetup(TestAra): + """ Tests the utils module """ + def setUp(self): + super(TestSetup, self).setUp() + + def tearDown(self): + super(TestSetup, self).tearDown() + + # TODO: Add tests :D diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index 6d96907c..aff0655b 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -12,39 +12,47 @@ To begin using ARA, you'll first need to set up Ansible so it knows about the the ARA :ref:`callback ` and, if necessary, the :ref:`ara_record ` and :ref:`ara_read ` modules. The callback and modules are bundled when installing ARA but you need to know -where they have been installed in order to let Ansible know where they are located. +where they have been installed in order to let Ansible know where they are +located. -.. tip:: +This location will be different depending on your operating system, how you are +installing ARA and whether you are using Python 2 or Python 3. - The location where ARA will be depends on your operating system and how it - is installed. - Here's some examples of where ARA can be found: +ARA ships a set of convenience Python modules to help you configure Ansible to +use it. - - ``/usr/lib/python2.7/site-packages/ara`` - - ``/usr/lib/python3.5/site-packages/ara`` - - ``$VIRTUAL_ENV/lib/python2.7/site-packages/ara`` +They can be used like so:: - If you're not sure where ARA will end up being installed, you can use this - snippet to print its location. It works in both Python 2 and Python 3:: + $ python -m ara.setup.path + /usr/lib/python2.7/site-packages/ara - python -c "import os,ara; print(os.path.dirname(ara.__file__))" + $ python -m ara.setup.action_plugins + /usr/lib/python2.7/site-packages/ara/plugins/actions + + $ python -m ara.setup.callback_plugins + /usr/lib/python2.7/site-packages/ara/plugins/callbacks + + $ python -m ara.setup.library + /usr/lib/python2.7/site-packages/ara/plugins/modules Using ansible.cfg ~~~~~~~~~~~~~~~~~ -Set up your `ansible.cfg`_ file to seek the callback and modules in the appropriate -directories:: +This sets up a new `ansible.cfg`_ file to load the callbacks and modules from +the appropriate locations:: - $ export ara_location=$(python -c "import os,ara; print(os.path.dirname(ara.__file__))") - $ cat > ansible.cfg <