prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  [healthchecks] the package_version check always checks for master/node packages regardless of host group
  #### Description
  
  When running `playbooks/byo/openshift-preflight/check.yml`, the `package_version` check reports failures on hosts that can't access the `atomic-openshift-{master,node}` packages even when this is expected, e.g. on etcd or lb hosts.
  
  
  ##### Version
  
  ```
  openshift-ansible-3.5.3-1-521-g3125e72
  ```
  
  ##### Steps To Reproduce
  1. Have a cluster with `[etcd]`, `[lb]` and/or additional "auxiliary" host groups
  2. Run the `playbooks/byo/openshift-preflight/check.yml` playbook
  
  
  ##### Expected Results
  Hosts would not report a failure when they have access to the packages they need.
  
  ##### Observed Results
  Hosts that don't have access to `atomic-openshift-{master,node}` packages in their configured repos are reported as failed, even when the hosts don't need these packages.
  Describe what is actually happening.
  
  ```
  $ ansible-playbook playbooks/byo/openshift-preflight/check.yml
  [...]
  Failure summary:
  
    1. Host:     etcd2.example.com
       Play:     run OpenShift health checks
       Task:     openshift_health_check
       Message:  One or more checks failed
       Details:  {'package_availability': {'_ansible_parsed': True,
                                           u'changed': False,
                                           u'invocation': {u'module_args': {u'packages': []}}},
                  'package_update': {'_ansible_parsed': True,
                                     u'changed': False,
                                     u'invocation': {u'module_args': {u'packages': []}}},
                  'package_version': {'_ansible_parsed': True,
                                      u'failed': True,
                                      u'invocation': {u'module_args': {u'prefix': u'atomic-openshift',
                                                                       u'version': u'v3.4'}},
                                      u'msg': u'Not all of the required packages are available at requested version 3.4:\n  atomic-openshift\n  atomic-openshift-master\n  atomic-openshift-node\nPlease check your subscriptions and enabled repositories.'}}
  ```
  
  ##### Additional Information
  
  The inventory file used here has:
  
  ```
  [OSEv3:children]
  masters
  nodes
  etcd
  lb
  dns
  
  # [...]
  
  [etcd]
  etcd2.example.com
  # [...]
  
  [lb]
  lb.example.com
  ```
  
  the hosts in *etcd*, *lb* and *dns* groups all fail the check.
  
  
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `roles/openshift_health_checker/openshift_checks/package_version.py`
  Content:
  ```
  1 # pylint: disable=missing-docstring
  2 from openshift_checks import OpenShiftCheck, get_var
  3 from openshift_checks.mixins import NotContainerizedMixin
  4 
  5 
  6 class PackageVersion(NotContainerizedMixin, OpenShiftCheck):
  7     """Check that available RPM packages match the required versions."""
  8 
  9     name = "package_version"
  10     tags = ["preflight"]
  11 
  12     def run(self, tmp, task_vars):
  13         rpm_prefix = get_var(task_vars, "openshift", "common", "service_type")
  14         openshift_release = get_var(task_vars, "openshift_release")
  15 
  16         args = {
  17             "prefix": rpm_prefix,
  18             "version": openshift_release,
  19         }
  20         return self.execute_module("aos_version", args, tmp, task_vars)
  21
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/roles/openshift_health_checker/openshift_checks/package_version.py b/roles/openshift_health_checker/openshift_checks/package_version.py
  --- a/roles/openshift_health_checker/openshift_checks/package_version.py
  +++ b/roles/openshift_health_checker/openshift_checks/package_version.py
  @@ -9,6 +9,13 @@
       name = "package_version"
       tags = ["preflight"]
   
  +    @classmethod
  +    def is_active(cls, task_vars):
  +        """Skip hosts that do not have package requirements."""
  +        group_names = get_var(task_vars, "group_names", default=[])
  +        master_or_node = 'masters' in group_names or 'nodes' in group_names
  +        return super(PackageVersion, cls).is_active(task_vars) and master_or_node
  +
       def run(self, tmp, task_vars):
           rpm_prefix = get_var(task_vars, "openshift", "common", "service_type")
           openshift_release = get_var(task_vars, "openshift_release")
  
verification_info: {"golden_diff": "diff --git a/roles/openshift_health_checker/openshift_checks/package_version.py b/roles/openshift_health_checker/openshift_checks/package_version.py\n--- a/roles/openshift_health_checker/openshift_checks/package_version.py\n+++ b/roles/openshift_health_checker/openshift_checks/package_version.py\n@@ -9,6 +9,13 @@\n     name = \"package_version\"\n     tags = [\"preflight\"]\n \n+    @classmethod\n+    def is_active(cls, task_vars):\n+        \"\"\"Skip hosts that do not have package requirements.\"\"\"\n+        group_names = get_var(task_vars, \"group_names\", default=[])\n+        master_or_node = 'masters' in group_names or 'nodes' in group_names\n+        return super(PackageVersion, cls).is_active(task_vars) and master_or_node\n+\n     def run(self, tmp, task_vars):\n         rpm_prefix = get_var(task_vars, \"openshift\", \"common\", \"service_type\")\n         openshift_release = get_var(task_vars, \"openshift_release\")\n", "issue": "[healthchecks] the package_version check always checks for master/node packages regardless of host group\n#### Description\r\n\r\nWhen running `playbooks/byo/openshift-preflight/check.yml`, the `package_version` check reports failures on hosts that can't access the `atomic-openshift-{master,node}` packages even when this is expected, e.g. on etcd or lb hosts.\r\n\r\n\r\n##### Version\r\n\r\n```\r\nopenshift-ansible-3.5.3-1-521-g3125e72\r\n```\r\n\r\n##### Steps To Reproduce\r\n1. Have a cluster with `[etcd]`, `[lb]` and/or additional \"auxiliary\" host groups\r\n2. Run the `playbooks/byo/openshift-preflight/check.yml` playbook\r\n\r\n\r\n##### Expected Results\r\nHosts would not report a failure when they have access to the packages they need.\r\n\r\n##### Observed Results\r\nHosts that don't have access to `atomic-openshift-{master,node}` packages in their configured repos are reported as failed, even when the hosts don't need these packages.\r\nDescribe what is actually happening.\r\n\r\n```\r\n$ ansible-playbook playbooks/byo/openshift-preflight/check.yml\r\n[...]\r\nFailure summary:\r\n\r\n  1. Host:     etcd2.example.com\r\n     Play:     run OpenShift health checks\r\n     Task:     openshift_health_check\r\n     Message:  One or more checks failed\r\n     Details:  {'package_availability': {'_ansible_parsed': True,\r\n                                         u'changed': False,\r\n                                         u'invocation': {u'module_args': {u'packages': []}}},\r\n                'package_update': {'_ansible_parsed': True,\r\n                                   u'changed': False,\r\n                                   u'invocation': {u'module_args': {u'packages': []}}},\r\n                'package_version': {'_ansible_parsed': True,\r\n                                    u'failed': True,\r\n                                    u'invocation': {u'module_args': {u'prefix': u'atomic-openshift',\r\n                                                                     u'version': u'v3.4'}},\r\n                                    u'msg': u'Not all of the required packages are available at requested version 3.4:\\n  atomic-openshift\\n  atomic-openshift-master\\n  atomic-openshift-node\\nPlease check your subscriptions and enabled repositories.'}}\r\n```\r\n\r\n##### Additional Information\r\n\r\nThe inventory file used here has:\r\n\r\n```\r\n[OSEv3:children]\r\nmasters\r\nnodes\r\netcd\r\nlb\r\ndns\r\n\r\n# [...]\r\n\r\n[etcd]\r\netcd2.example.com\r\n# [...]\r\n\r\n[lb]\r\nlb.example.com\r\n```\r\n\r\nthe hosts in *etcd*, *lb* and *dns* groups all fail the check.\r\n\r\n\r\n\n", "before_files": [{"content": "# pylint: disable=missing-docstring\nfrom openshift_checks import OpenShiftCheck, get_var\nfrom openshift_checks.mixins import NotContainerizedMixin\n\n\nclass PackageVersion(NotContainerizedMixin, OpenShiftCheck):\n    \"\"\"Check that available RPM packages match the required versions.\"\"\"\n\n    name = \"package_version\"\n    tags = [\"preflight\"]\n\n    def run(self, tmp, task_vars):\n        rpm_prefix = get_var(task_vars, \"openshift\", \"common\", \"service_type\")\n        openshift_release = get_var(task_vars, \"openshift_release\")\n\n        args = {\n            \"prefix\": rpm_prefix,\n            \"version\": openshift_release,\n        }\n        return self.execute_module(\"aos_version\", args, tmp, task_vars)\n", "path": "roles/openshift_health_checker/openshift_checks/package_version.py"}], "after_files": [{"content": "# pylint: disable=missing-docstring\nfrom openshift_checks import OpenShiftCheck, get_var\nfrom openshift_checks.mixins import NotContainerizedMixin\n\n\nclass PackageVersion(NotContainerizedMixin, OpenShiftCheck):\n    \"\"\"Check that available RPM packages match the required versions.\"\"\"\n\n    name = \"package_version\"\n    tags = [\"preflight\"]\n\n    @classmethod\n    def is_active(cls, task_vars):\n        \"\"\"Skip hosts that do not have package requirements.\"\"\"\n        group_names = get_var(task_vars, \"group_names\", default=[])\n        master_or_node = 'masters' in group_names or 'nodes' in group_names\n        return super(PackageVersion, cls).is_active(task_vars) and master_or_node\n\n    def run(self, tmp, task_vars):\n        rpm_prefix = get_var(task_vars, \"openshift\", \"common\", \"service_type\")\n        openshift_release = get_var(task_vars, \"openshift_release\")\n\n        args = {\n            \"prefix\": rpm_prefix,\n            \"version\": openshift_release,\n        }\n        return self.execute_module(\"aos_version\", args, tmp, task_vars)\n", "path": "roles/openshift_health_checker/openshift_checks/package_version.py"}]}