Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Should install RHO's Ansible playbook, roles and library as package_data or data_files? #238

Closed
elyezer opened this issue Aug 28, 2017 · 4 comments

Comments

@elyezer
Copy link

elyezer commented Aug 28, 2017

Specify type:

  • Enhancement

Description:

When installing RHO from source code it would be great if its Ansible playbook, roles and library was installed as package_data. The expected workflow is that one would clone the repository and run all commands from within the project's root directory.

But since RHO is a Python package someone would want to just pip install git+https://github.com/quipucords/rho.git on a virtual environment. Doing that the project will be cloned but RHO's Ansible playbook, roles and library won't be on the same directory.

Doing that will also ease the functional testing and test coverage measurement. The functional tests are running rho from an isolated filesystem (see the isolated_filesystem context manager here https://github.com/quipucords/camayoc/blob/master/camayoc/utils.py).


Version of rho:

8f9336f

@chambridge
Copy link

The following seems to provide info on steps to make this possible:
http://python-packaging.readthedocs.io/en/latest/non-code-files.html

@elyezer
Copy link
Author

elyezer commented Aug 29, 2017

Looking over the suggestions made by https://packaging.python.org we can see on the sample project how the package_data and data_files can be included https://github.com/pypa/sampleproject/blob/master/setup.py#L92-L103.

@elyezer
Copy link
Author

elyezer commented Aug 29, 2017

Tried with this patch:

diff --git a/rho/scancommand.py b/rho/scancommand.py
index f222c92..7fe446e 100644
--- a/rho/scancommand.py
+++ b/rho/scancommand.py
@@ -491,13 +491,23 @@ class ScanCommand(CliCommand):
         ansible_vars = {'facts_to_collect': self.facts_to_collect,
                         'report_path': report_path}
 
-        playbook = utilities.PLAYBOOK_DEV_PATH
-        if not os.path.isfile(playbook):
-            playbook = utilities.PLAYBOOK_RPM_PATH
-            if not os.path.isfile(playbook):
-                print(_("rho scan playbook not found locally or in '%s'")
-                      % playbook)
-                sys.exit(1)
+        playbook = None
+        paths = [
+            utilities.PLAYBOOK_DEV_PATH,
+            os.path.join(
+                sys.prefix, 'rho_ansible', utilities.PLAYBOOK_DEV_PATH),
+            utilities.PLAYBOOK_RPM_PATH,
+        ]
+        for path in paths:
+            if os.path.isfile(path):
+                playbook = path
+                break
+        if not playbook:
+            print(
+                _("rho scan playbook not found locally or in '%s'")
+                % ', '.join(paths)
+            )
+            sys.exit(1)
 
         cmd_string = ('ansible-playbook {playbook} '
                       '-i data/{profile}_hosts.yml -f {forks} '
diff --git a/setup.py b/setup.py
index 7e3bfa3..0bd8d4b 100755
--- a/setup.py
+++ b/setup.py
@@ -85,9 +85,23 @@ def get_locale_paths():
     return data_paths
 
 
+def get_rho_ansible_paths():
+    rho_ansible_path = 'rho_ansible'
+    data_paths = [
+        (rho_ansible_path, ['rho_playbook.yml']),
+    ]
+    for pattern in ('library/*', 'roles/*/tasks/*.yml'):
+        for path in glob.glob(pattern):
+            dirname = os.path.dirname(path)
+            data_paths.append(
+                (os.path.join(rho_ansible_path, dirname), glob.glob(pattern))
+            )
+    return data_paths
+
+
 def get_data_files():
     gen_mo_files()
-    return get_locale_paths()
+    return get_locale_paths() + get_rho_ansible_paths()
 
 
 setup(

And this MANIFEST.in file:

include LICENSE

include rho_playbook.yml
recursive-include library *
recursive-include roles *

But for some reason the report file is not being generated even though the scan command is printing the message that the report file was generated.

@elyezer
Copy link
Author

elyezer commented Aug 30, 2017

I am going to close this issue, trying to include the playbook as data_files is something that does not work consistently across tools pypa/sampleproject#30 (comment)

And also when installing in editable format the data_files are not created.

The approach to test from the source code will be running from within the RHO root directory, have all rho_playbook.yml related roles and library files on the cwd or configure ansible to look into the place where the library is http://docs.ansible.com/ansible/latest/intro_configuration.html#library

@elyezer elyezer closed this as completed Aug 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants