We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
junos_package.py: package_version undefined
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

junos_package
##### ANSIBLE VERSION

devel
##### CONFIGURATION
##### OS / ENVIRONMENT
##### SUMMARY

https://github.com/ansible/ansible-modules-core/blame/devel/network/junos/junos_package.py#L141

`wants_ver = module.params['version'] or package_version(module)`

I can't find anywhere in the `ansible/ansible` code base where `package_version` is defined


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `network/junos/junos_package.py`
Content:
```
1 #!/usr/bin/python
2 #
3 # This file is part of Ansible
4 #
5 # Ansible is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Ansible is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
17 #
18 
19 DOCUMENTATION = """
20 ---
21 module: junos_package
22 version_added: "2.1"
23 author: "Peter Sprygada (@privateip)"
24 short_description: Installs packages on remote devices running Junos
25 description:
26   - This module can install new and updated packages on remote
27     devices running Junos.  The module will compare the specified
28     package with the one running on the remote device and install
29     the specified version if there is a mismatch
30 extends_documentation_fragment: junos
31 options:
32   src:
33     description:
34       - The I(src) argument specifies the path to the source package to be
35         installed on the remote device in the advent of a version mismatch.
36         The I(src) argument can be either a localized path or a full
37         path to the package file to install.
38     required: true
39     default: null
40     aliases: ['package']
41   version:
42     description:
43       - The I(version) argument can be used to explicitly specify the
44         version of the package that should be installed on the remote
45         device.  If the I(version) argument is not specified, then
46         the version is extracts from the I(src) filename.
47     required: false
48     default: null
49   reboot:
50     description:
51       - In order for a package to take effect, the remote device must be
52         restarted.  When enabled, this argument will instruct the module
53         to reboot the device once the updated package has been installed.
54         If disabled or the remote package does not need to be changed,
55         the device will not be started.
56     required: true
57     default: true
58     choices: ['true', 'false']
59   no_copy:
60     description:
61       - The I(no_copy) argument is responsible for instructing the remote
62         device on where to install the package from.  When enabled, the
63         package is transferred to the remote device prior to installing.
64     required: false
65     default: false
66     choices: ['true', 'false']
67   force:
68     description:
69       - The I(force) argument instructs the module to bypass the package
70         version check and install the packaged identified in I(src) on
71         the remote device.
72     required: true
73     default: false
74     choices: ['true', 'false']
75 requirements:
76   - junos-eznc
77 notes:
78   - This module requires the netconf system service be enabled on
79     the remote device being managed
80 """
81 
82 EXAMPLES = """
83 # the required set of connection arguments have been purposely left off
84 # the examples for brevity
85 
86 - name: install local package on remote device
87   junos_package:
88     src: junos-vsrx-12.1X46-D10.2-domestic.tgz
89 
90 - name: install local package on remote device without rebooting
91   junos_package:
92     src: junos-vsrx-12.1X46-D10.2-domestic.tgz
93     reboot: no
94 """
95 
96 try:
97     from jnpr.junos.utils.sw import SW
98     HAS_SW = True
99 except ImportError:
100     HAS_SW = False
101 
102 def install_package(module):
103     junos = SW(module.connection.device)
104     package = module.params['src']
105     no_copy = module.params['no_copy']
106 
107     progress_log = lambda x, y: module.log(y)
108 
109     module.log('installing package')
110     result = junos.install(package, progress=progress_log, no_copy=no_copy)
111 
112     if not result:
113         module.fail_json(msg='Unable to install package on device')
114 
115     if module.params['reboot']:
116         module.log('rebooting system')
117         junos.reboot()
118 
119 
120 def main():
121     spec = dict(
122         src=dict(type='path', required=True, aliases=['package']),
123         version=dict(),
124         reboot=dict(type='bool', default=True),
125         no_copy=dict(default=False, type='bool'),
126         force=dict(type='bool', default=False),
127         transport=dict(default='netconf', choices=['netconf'])
128     )
129 
130     module = get_module(argument_spec=spec,
131                         supports_check_mode=True)
132 
133     if not HAS_SW:
134         module.fail_json(msg='Missing jnpr.junos.utils.sw module')
135 
136     result = dict(changed=False)
137 
138     do_upgrade = module.params['force'] or False
139     if not module.params['force']:
140         has_ver = module.get_facts().get('version')
141         wants_ver = module.params['version'] or package_version(module)
142         do_upgrade = has_ver != wants_ver
143 
144     if do_upgrade:
145         if not module.check_mode:
146             install_package(module)
147         result['changed'] = True
148 
149     module.exit_json(**result)
150 
151 from ansible.module_utils.basic import *
152 from ansible.module_utils.junos import *
153 
154 if __name__ == '__main__':
155     main()
156
```
--- 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()

```

diff --git a/network/junos/junos_package.py b/network/junos/junos_package.py
--- a/network/junos/junos_package.py
+++ b/network/junos/junos_package.py
@@ -92,6 +92,7 @@
     src: junos-vsrx-12.1X46-D10.2-domestic.tgz
     reboot: no
 """
+from ansible.module_utils.junos import NetworkModule
 
 try:
     from jnpr.junos.utils.sw import SW
@@ -127,8 +128,8 @@
         transport=dict(default='netconf', choices=['netconf'])
     )
 
-    module = get_module(argument_spec=spec,
-                        supports_check_mode=True)
+    module = NetworkModule(argument_spec=spec,
+                           supports_check_mode=True)
 
     if not HAS_SW:
         module.fail_json(msg='Missing jnpr.junos.utils.sw module')
@@ -137,8 +138,8 @@
 
     do_upgrade = module.params['force'] or False
     if not module.params['force']:
-        has_ver = module.get_facts().get('version')
-        wants_ver = module.params['version'] or package_version(module)
+        has_ver = module.connection.get_facts().get('version')
+        wants_ver = module.params['version']
         do_upgrade = has_ver != wants_ver
 
     if do_upgrade:
@@ -148,8 +149,6 @@
 
     module.exit_json(**result)
 
-from ansible.module_utils.basic import *
-from ansible.module_utils.junos import *
 
 if __name__ == '__main__':
     main()

{"golden_diff": "diff --git a/network/junos/junos_package.py b/network/junos/junos_package.py\n--- a/network/junos/junos_package.py\n+++ b/network/junos/junos_package.py\n@@ -92,6 +92,7 @@\n     src: junos-vsrx-12.1X46-D10.2-domestic.tgz\n     reboot: no\n \"\"\"\n+from ansible.module_utils.junos import NetworkModule\n \n try:\n     from jnpr.junos.utils.sw import SW\n@@ -127,8 +128,8 @@\n         transport=dict(default='netconf', choices=['netconf'])\n     )\n \n-    module = get_module(argument_spec=spec,\n-                        supports_check_mode=True)\n+    module = NetworkModule(argument_spec=spec,\n+                           supports_check_mode=True)\n \n     if not HAS_SW:\n         module.fail_json(msg='Missing jnpr.junos.utils.sw module')\n@@ -137,8 +138,8 @@\n \n     do_upgrade = module.params['force'] or False\n     if not module.params['force']:\n-        has_ver = module.get_facts().get('version')\n-        wants_ver = module.params['version'] or package_version(module)\n+        has_ver = module.connection.get_facts().get('version')\n+        wants_ver = module.params['version']\n         do_upgrade = has_ver != wants_ver\n \n     if do_upgrade:\n@@ -148,8 +149,6 @@\n \n     module.exit_json(**result)\n \n-from ansible.module_utils.basic import *\n-from ansible.module_utils.junos import *\n \n if __name__ == '__main__':\n     main()\n", "issue": "junos_package.py: package_version undefined\n##### ISSUE TYPE\n- Bug Report\n##### COMPONENT NAME\n\njunos_package\n##### ANSIBLE VERSION\n\ndevel\n##### CONFIGURATION\n##### OS / ENVIRONMENT\n##### SUMMARY\n\nhttps://github.com/ansible/ansible-modules-core/blame/devel/network/junos/junos_package.py#L141\n\n`wants_ver = module.params['version'] or package_version(module)`\n\nI can't find anywhere in the `ansible/ansible` code base where `package_version` is defined\n\n", "before_files": [{"content": "#!/usr/bin/python\n#\n# This file is part of Ansible\n#\n# Ansible is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# Ansible is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n#\n\nDOCUMENTATION = \"\"\"\n---\nmodule: junos_package\nversion_added: \"2.1\"\nauthor: \"Peter Sprygada (@privateip)\"\nshort_description: Installs packages on remote devices running Junos\ndescription:\n  - This module can install new and updated packages on remote\n    devices running Junos.  The module will compare the specified\n    package with the one running on the remote device and install\n    the specified version if there is a mismatch\nextends_documentation_fragment: junos\noptions:\n  src:\n    description:\n      - The I(src) argument specifies the path to the source package to be\n        installed on the remote device in the advent of a version mismatch.\n        The I(src) argument can be either a localized path or a full\n        path to the package file to install.\n    required: true\n    default: null\n    aliases: ['package']\n  version:\n    description:\n      - The I(version) argument can be used to explicitly specify the\n        version of the package that should be installed on the remote\n        device.  If the I(version) argument is not specified, then\n        the version is extracts from the I(src) filename.\n    required: false\n    default: null\n  reboot:\n    description:\n      - In order for a package to take effect, the remote device must be\n        restarted.  When enabled, this argument will instruct the module\n        to reboot the device once the updated package has been installed.\n        If disabled or the remote package does not need to be changed,\n        the device will not be started.\n    required: true\n    default: true\n    choices: ['true', 'false']\n  no_copy:\n    description:\n      - The I(no_copy) argument is responsible for instructing the remote\n        device on where to install the package from.  When enabled, the\n        package is transferred to the remote device prior to installing.\n    required: false\n    default: false\n    choices: ['true', 'false']\n  force:\n    description:\n      - The I(force) argument instructs the module to bypass the package\n        version check and install the packaged identified in I(src) on\n        the remote device.\n    required: true\n    default: false\n    choices: ['true', 'false']\nrequirements:\n  - junos-eznc\nnotes:\n  - This module requires the netconf system service be enabled on\n    the remote device being managed\n\"\"\"\n\nEXAMPLES = \"\"\"\n# the required set of connection arguments have been purposely left off\n# the examples for brevity\n\n- name: install local package on remote device\n  junos_package:\n    src: junos-vsrx-12.1X46-D10.2-domestic.tgz\n\n- name: install local package on remote device without rebooting\n  junos_package:\n    src: junos-vsrx-12.1X46-D10.2-domestic.tgz\n    reboot: no\n\"\"\"\n\ntry:\n    from jnpr.junos.utils.sw import SW\n    HAS_SW = True\nexcept ImportError:\n    HAS_SW = False\n\ndef install_package(module):\n    junos = SW(module.connection.device)\n    package = module.params['src']\n    no_copy = module.params['no_copy']\n\n    progress_log = lambda x, y: module.log(y)\n\n    module.log('installing package')\n    result = junos.install(package, progress=progress_log, no_copy=no_copy)\n\n    if not result:\n        module.fail_json(msg='Unable to install package on device')\n\n    if module.params['reboot']:\n        module.log('rebooting system')\n        junos.reboot()\n\n\ndef main():\n    spec = dict(\n        src=dict(type='path', required=True, aliases=['package']),\n        version=dict(),\n        reboot=dict(type='bool', default=True),\n        no_copy=dict(default=False, type='bool'),\n        force=dict(type='bool', default=False),\n        transport=dict(default='netconf', choices=['netconf'])\n    )\n\n    module = get_module(argument_spec=spec,\n                        supports_check_mode=True)\n\n    if not HAS_SW:\n        module.fail_json(msg='Missing jnpr.junos.utils.sw module')\n\n    result = dict(changed=False)\n\n    do_upgrade = module.params['force'] or False\n    if not module.params['force']:\n        has_ver = module.get_facts().get('version')\n        wants_ver = module.params['version'] or package_version(module)\n        do_upgrade = has_ver != wants_ver\n\n    if do_upgrade:\n        if not module.check_mode:\n            install_package(module)\n        result['changed'] = True\n\n    module.exit_json(**result)\n\nfrom ansible.module_utils.basic import *\nfrom ansible.module_utils.junos import *\n\nif __name__ == '__main__':\n    main()\n", "path": "network/junos/junos_package.py"}], "after_files": [{"content": "#!/usr/bin/python\n#\n# This file is part of Ansible\n#\n# Ansible is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# Ansible is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n#\n\nDOCUMENTATION = \"\"\"\n---\nmodule: junos_package\nversion_added: \"2.1\"\nauthor: \"Peter Sprygada (@privateip)\"\nshort_description: Installs packages on remote devices running Junos\ndescription:\n  - This module can install new and updated packages on remote\n    devices running Junos.  The module will compare the specified\n    package with the one running on the remote device and install\n    the specified version if there is a mismatch\nextends_documentation_fragment: junos\noptions:\n  src:\n    description:\n      - The I(src) argument specifies the path to the source package to be\n        installed on the remote device in the advent of a version mismatch.\n        The I(src) argument can be either a localized path or a full\n        path to the package file to install.\n    required: true\n    default: null\n    aliases: ['package']\n  version:\n    description:\n      - The I(version) argument can be used to explicitly specify the\n        version of the package that should be installed on the remote\n        device.  If the I(version) argument is not specified, then\n        the version is extracts from the I(src) filename.\n    required: false\n    default: null\n  reboot:\n    description:\n      - In order for a package to take effect, the remote device must be\n        restarted.  When enabled, this argument will instruct the module\n        to reboot the device once the updated package has been installed.\n        If disabled or the remote package does not need to be changed,\n        the device will not be started.\n    required: true\n    default: true\n    choices: ['true', 'false']\n  no_copy:\n    description:\n      - The I(no_copy) argument is responsible for instructing the remote\n        device on where to install the package from.  When enabled, the\n        package is transferred to the remote device prior to installing.\n    required: false\n    default: false\n    choices: ['true', 'false']\n  force:\n    description:\n      - The I(force) argument instructs the module to bypass the package\n        version check and install the packaged identified in I(src) on\n        the remote device.\n    required: true\n    default: false\n    choices: ['true', 'false']\nrequirements:\n  - junos-eznc\nnotes:\n  - This module requires the netconf system service be enabled on\n    the remote device being managed\n\"\"\"\n\nEXAMPLES = \"\"\"\n# the required set of connection arguments have been purposely left off\n# the examples for brevity\n\n- name: install local package on remote device\n  junos_package:\n    src: junos-vsrx-12.1X46-D10.2-domestic.tgz\n\n- name: install local package on remote device without rebooting\n  junos_package:\n    src: junos-vsrx-12.1X46-D10.2-domestic.tgz\n    reboot: no\n\"\"\"\nfrom ansible.module_utils.junos import NetworkModule\n\ntry:\n    from jnpr.junos.utils.sw import SW\n    HAS_SW = True\nexcept ImportError:\n    HAS_SW = False\n\ndef install_package(module):\n    junos = SW(module.connection.device)\n    package = module.params['src']\n    no_copy = module.params['no_copy']\n\n    progress_log = lambda x, y: module.log(y)\n\n    module.log('installing package')\n    result = junos.install(package, progress=progress_log, no_copy=no_copy)\n\n    if not result:\n        module.fail_json(msg='Unable to install package on device')\n\n    if module.params['reboot']:\n        module.log('rebooting system')\n        junos.reboot()\n\n\ndef main():\n    spec = dict(\n        src=dict(type='path', required=True, aliases=['package']),\n        version=dict(),\n        reboot=dict(type='bool', default=True),\n        no_copy=dict(default=False, type='bool'),\n        force=dict(type='bool', default=False),\n        transport=dict(default='netconf', choices=['netconf'])\n    )\n\n    module = NetworkModule(argument_spec=spec,\n                           supports_check_mode=True)\n\n    if not HAS_SW:\n        module.fail_json(msg='Missing jnpr.junos.utils.sw module')\n\n    result = dict(changed=False)\n\n    do_upgrade = module.params['force'] or False\n    if not module.params['force']:\n        has_ver = module.connection.get_facts().get('version')\n        wants_ver = module.params['version']\n        do_upgrade = has_ver != wants_ver\n\n    if do_upgrade:\n        if not module.check_mode:\n            install_package(module)\n        result['changed'] = True\n\n    module.exit_json(**result)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "network/junos/junos_package.py"}]}