prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  alternatives should allow link priorty as an optional parameter
  **Issue Type:**  “Feature Idea”
  **Ansible Version:** 1.9.1
  **Ansible Configuration:** Stock configuration
  **Environment:** Ubuntu 14.04 x64 managing an Ubuntu 14.04 x64 machine
  
  **Summary:** The alternatives module should allow you to pass in the link priority as an optional parameter. Currently the link priority is hard coded in the module as highlighted below:
  
  https://github.com/ansible/ansible-modules-extras/blob/devel/system/alternatives.py#L61
  
  Ansible should only report a change when the priority and link stayed the same.
  
  **Steps To Reproduce:** None, feature idea
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `system/alternatives.py`
  Content:
  ```
  1 #!/usr/bin/python
  2 # -*- coding: utf-8 -*-
  3 
  4 """
  5 Ansible module to manage symbolic link alternatives.
  6 (c) 2014, Gabe Mulley <gabe.mulley@gmail.com>
  7 (c) 2015, David Wittman <dwittman@gmail.com>
  8 
  9 This file is part of Ansible
  10 
  11 Ansible is free software: you can redistribute it and/or modify
  12 it under the terms of the GNU General Public License as published by
  13 the Free Software Foundation, either version 3 of the License, or
  14 (at your option) any later version.
  15 
  16 Ansible is distributed in the hope that it will be useful,
  17 but WITHOUT ANY WARRANTY; without even the implied warranty of
  18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19 GNU General Public License for more details.
  20 
  21 You should have received a copy of the GNU General Public License
  22 along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
  23 """
  24 
  25 DOCUMENTATION = '''
  26 ---
  27 module: alternatives
  28 short_description: Manages alternative programs for common commands
  29 description:
  30     - Manages symbolic links using the 'update-alternatives' tool
  31     - Useful when multiple programs are installed but provide similar functionality (e.g. different editors).
  32 version_added: "1.6"
  33 author:
  34     - "David Wittman (@DavidWittman)"
  35     - "Gabe Mulley (@mulby)"
  36 options:
  37   name:
  38     description:
  39       - The generic name of the link.
  40     required: true
  41   path:
  42     description:
  43       - The path to the real executable that the link should point to.
  44     required: true
  45   link:
  46     description:
  47       - The path to the symbolic link that should point to the real executable.
  48       - This option is required on RHEL-based distributions
  49     required: false
  50 requirements: [ update-alternatives ]
  51 '''
  52 
  53 EXAMPLES = '''
  54 - name: correct java version selected
  55   alternatives: name=java path=/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
  56 
  57 - name: alternatives link created
  58   alternatives: name=hadoop-conf link=/etc/hadoop/conf path=/etc/hadoop/conf.ansible
  59 '''
  60 
  61 DEFAULT_LINK_PRIORITY = 50
  62 
  63 import re
  64 from ansible.module_utils.basic import *
  65 from ansible.module_utils.pycompat24 import get_exception
  66 
  67 
  68 def main():
  69 
  70     module = AnsibleModule(
  71         argument_spec = dict(
  72             name = dict(required=True),
  73             path = dict(required=True, type='path'),
  74             link = dict(required=False, type='path'),
  75         ),
  76         supports_check_mode=True,
  77     )
  78 
  79     params = module.params
  80     name = params['name']
  81     path = params['path']
  82     link = params['link']
  83 
  84     UPDATE_ALTERNATIVES = module.get_bin_path('update-alternatives',True)
  85 
  86     current_path = None
  87     all_alternatives = []
  88 
  89     # Run `update-alternatives --display <name>` to find existing alternatives
  90     (rc, display_output, _) = module.run_command(
  91         ['env', 'LC_ALL=C', UPDATE_ALTERNATIVES, '--display', name]
  92     )
  93 
  94     if rc == 0:
  95         # Alternatives already exist for this link group
  96         # Parse the output to determine the current path of the symlink and
  97         # available alternatives
  98         current_path_regex = re.compile(r'^\s*link currently points to (.*)$',
  99                                         re.MULTILINE)
  100         alternative_regex = re.compile(r'^(\/.*)\s-\spriority', re.MULTILINE)
  101 
  102         current_path = current_path_regex.search(display_output).group(1)
  103         all_alternatives = alternative_regex.findall(display_output)
  104 
  105         if not link:
  106             # Read the current symlink target from `update-alternatives --query`
  107             # in case we need to install the new alternative before setting it.
  108             #
  109             # This is only compatible on Debian-based systems, as the other
  110             # alternatives don't have --query available
  111             rc, query_output, _ = module.run_command(
  112                 ['env', 'LC_ALL=C', UPDATE_ALTERNATIVES, '--query', name]
  113             )
  114             if rc == 0:
  115                 for line in query_output.splitlines():
  116                     if line.startswith('Link:'):
  117                         link = line.split()[1]
  118                         break
  119 
  120     if current_path != path:
  121         if module.check_mode:
  122             module.exit_json(changed=True, current_path=current_path)
  123         try:
  124             # install the requested path if necessary
  125             if path not in all_alternatives:
  126                 if not link:
  127                     module.fail_json(msg="Needed to install the alternative, but unable to do so as we are missing the link")
  128 
  129                 module.run_command(
  130                     [UPDATE_ALTERNATIVES, '--install', link, name, path, str(DEFAULT_LINK_PRIORITY)],
  131                     check_rc=True
  132                 )
  133 
  134             # select the requested path
  135             module.run_command(
  136                 [UPDATE_ALTERNATIVES, '--set', name, path],
  137                 check_rc=True
  138             )
  139 
  140             module.exit_json(changed=True)
  141         except subprocess.CalledProcessError:
  142             e = get_exception()
  143             module.fail_json(msg=str(dir(cpe)))
  144     else:
  145         module.exit_json(changed=False)
  146 
  147 
  148 main()
  149
  ```
  --- 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/system/alternatives.py b/system/alternatives.py
  --- a/system/alternatives.py
  +++ b/system/alternatives.py
  @@ -47,6 +47,10 @@
         - The path to the symbolic link that should point to the real executable.
         - This option is required on RHEL-based distributions
       required: false
  +  priority:
  +    description:
  +      - The priority of the alternative
  +    required: false
   requirements: [ update-alternatives ]
   '''
   
  @@ -56,9 +60,10 @@
   
   - name: alternatives link created
     alternatives: name=hadoop-conf link=/etc/hadoop/conf path=/etc/hadoop/conf.ansible
  -'''
   
  -DEFAULT_LINK_PRIORITY = 50
  +- name: make java 32 bit an alternative with low priority
  +  alternatives: name=java path=/usr/lib/jvm/java-7-openjdk-i386/jre/bin/java priority=-10
  +'''
   
   import re
   from ansible.module_utils.basic import *
  @@ -72,6 +77,8 @@
               name = dict(required=True),
               path = dict(required=True, type='path'),
               link = dict(required=False, type='path'),
  +            priority = dict(required=False, type='int',
  +                            default=50),
           ),
           supports_check_mode=True,
       )
  @@ -80,6 +87,7 @@
       name = params['name']
       path = params['path']
       link = params['link']
  +    priority = params['priority']
   
       UPDATE_ALTERNATIVES = module.get_bin_path('update-alternatives',True)
   
  @@ -127,7 +135,7 @@
                       module.fail_json(msg="Needed to install the alternative, but unable to do so as we are missing the link")
   
                   module.run_command(
  -                    [UPDATE_ALTERNATIVES, '--install', link, name, path, str(DEFAULT_LINK_PRIORITY)],
  +                    [UPDATE_ALTERNATIVES, '--install', link, name, path, str(priority)],
                       check_rc=True
                   )
  
verification_info: {"golden_diff": "diff --git a/system/alternatives.py b/system/alternatives.py\n--- a/system/alternatives.py\n+++ b/system/alternatives.py\n@@ -47,6 +47,10 @@\n       - The path to the symbolic link that should point to the real executable.\n       - This option is required on RHEL-based distributions\n     required: false\n+  priority:\n+    description:\n+      - The priority of the alternative\n+    required: false\n requirements: [ update-alternatives ]\n '''\n \n@@ -56,9 +60,10 @@\n \n - name: alternatives link created\n   alternatives: name=hadoop-conf link=/etc/hadoop/conf path=/etc/hadoop/conf.ansible\n-'''\n \n-DEFAULT_LINK_PRIORITY = 50\n+- name: make java 32 bit an alternative with low priority\n+  alternatives: name=java path=/usr/lib/jvm/java-7-openjdk-i386/jre/bin/java priority=-10\n+'''\n \n import re\n from ansible.module_utils.basic import *\n@@ -72,6 +77,8 @@\n             name = dict(required=True),\n             path = dict(required=True, type='path'),\n             link = dict(required=False, type='path'),\n+            priority = dict(required=False, type='int',\n+                            default=50),\n         ),\n         supports_check_mode=True,\n     )\n@@ -80,6 +87,7 @@\n     name = params['name']\n     path = params['path']\n     link = params['link']\n+    priority = params['priority']\n \n     UPDATE_ALTERNATIVES = module.get_bin_path('update-alternatives',True)\n \n@@ -127,7 +135,7 @@\n                     module.fail_json(msg=\"Needed to install the alternative, but unable to do so as we are missing the link\")\n \n                 module.run_command(\n-                    [UPDATE_ALTERNATIVES, '--install', link, name, path, str(DEFAULT_LINK_PRIORITY)],\n+                    [UPDATE_ALTERNATIVES, '--install', link, name, path, str(priority)],\n                     check_rc=True\n                 )\n", "issue": "alternatives should allow link priorty as an optional parameter\n**Issue Type:**  \u201cFeature Idea\u201d\n**Ansible Version:** 1.9.1\n**Ansible Configuration:** Stock configuration\n**Environment:** Ubuntu 14.04 x64 managing an Ubuntu 14.04 x64 machine\n\n**Summary:** The alternatives module should allow you to pass in the link priority as an optional parameter. Currently the link priority is hard coded in the module as highlighted below:\n\nhttps://github.com/ansible/ansible-modules-extras/blob/devel/system/alternatives.py#L61\n\nAnsible should only report a change when the priority and link stayed the same.\n\n**Steps To Reproduce:** None, feature idea\n\n", "before_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\n\"\"\"\nAnsible module to manage symbolic link alternatives.\n(c) 2014, Gabe Mulley <gabe.mulley@gmail.com>\n(c) 2015, David Wittman <dwittman@gmail.com>\n\nThis file is part of Ansible\n\nAnsible is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nAnsible is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n\"\"\"\n\nDOCUMENTATION = '''\n---\nmodule: alternatives\nshort_description: Manages alternative programs for common commands\ndescription:\n    - Manages symbolic links using the 'update-alternatives' tool\n    - Useful when multiple programs are installed but provide similar functionality (e.g. different editors).\nversion_added: \"1.6\"\nauthor:\n    - \"David Wittman (@DavidWittman)\"\n    - \"Gabe Mulley (@mulby)\"\noptions:\n  name:\n    description:\n      - The generic name of the link.\n    required: true\n  path:\n    description:\n      - The path to the real executable that the link should point to.\n    required: true\n  link:\n    description:\n      - The path to the symbolic link that should point to the real executable.\n      - This option is required on RHEL-based distributions\n    required: false\nrequirements: [ update-alternatives ]\n'''\n\nEXAMPLES = '''\n- name: correct java version selected\n  alternatives: name=java path=/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java\n\n- name: alternatives link created\n  alternatives: name=hadoop-conf link=/etc/hadoop/conf path=/etc/hadoop/conf.ansible\n'''\n\nDEFAULT_LINK_PRIORITY = 50\n\nimport re\nfrom ansible.module_utils.basic import *\nfrom ansible.module_utils.pycompat24 import get_exception\n\n\ndef main():\n\n    module = AnsibleModule(\n        argument_spec = dict(\n            name = dict(required=True),\n            path = dict(required=True, type='path'),\n            link = dict(required=False, type='path'),\n        ),\n        supports_check_mode=True,\n    )\n\n    params = module.params\n    name = params['name']\n    path = params['path']\n    link = params['link']\n\n    UPDATE_ALTERNATIVES = module.get_bin_path('update-alternatives',True)\n\n    current_path = None\n    all_alternatives = []\n\n    # Run `update-alternatives --display <name>` to find existing alternatives\n    (rc, display_output, _) = module.run_command(\n        ['env', 'LC_ALL=C', UPDATE_ALTERNATIVES, '--display', name]\n    )\n\n    if rc == 0:\n        # Alternatives already exist for this link group\n        # Parse the output to determine the current path of the symlink and\n        # available alternatives\n        current_path_regex = re.compile(r'^\\s*link currently points to (.*)$',\n                                        re.MULTILINE)\n        alternative_regex = re.compile(r'^(\\/.*)\\s-\\spriority', re.MULTILINE)\n\n        current_path = current_path_regex.search(display_output).group(1)\n        all_alternatives = alternative_regex.findall(display_output)\n\n        if not link:\n            # Read the current symlink target from `update-alternatives --query`\n            # in case we need to install the new alternative before setting it.\n            #\n            # This is only compatible on Debian-based systems, as the other\n            # alternatives don't have --query available\n            rc, query_output, _ = module.run_command(\n                ['env', 'LC_ALL=C', UPDATE_ALTERNATIVES, '--query', name]\n            )\n            if rc == 0:\n                for line in query_output.splitlines():\n                    if line.startswith('Link:'):\n                        link = line.split()[1]\n                        break\n\n    if current_path != path:\n        if module.check_mode:\n            module.exit_json(changed=True, current_path=current_path)\n        try:\n            # install the requested path if necessary\n            if path not in all_alternatives:\n                if not link:\n                    module.fail_json(msg=\"Needed to install the alternative, but unable to do so as we are missing the link\")\n\n                module.run_command(\n                    [UPDATE_ALTERNATIVES, '--install', link, name, path, str(DEFAULT_LINK_PRIORITY)],\n                    check_rc=True\n                )\n\n            # select the requested path\n            module.run_command(\n                [UPDATE_ALTERNATIVES, '--set', name, path],\n                check_rc=True\n            )\n\n            module.exit_json(changed=True)\n        except subprocess.CalledProcessError:\n            e = get_exception()\n            module.fail_json(msg=str(dir(cpe)))\n    else:\n        module.exit_json(changed=False)\n\n\nmain()\n", "path": "system/alternatives.py"}], "after_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\n\"\"\"\nAnsible module to manage symbolic link alternatives.\n(c) 2014, Gabe Mulley <gabe.mulley@gmail.com>\n(c) 2015, David Wittman <dwittman@gmail.com>\n\nThis file is part of Ansible\n\nAnsible is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nAnsible is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n\"\"\"\n\nDOCUMENTATION = '''\n---\nmodule: alternatives\nshort_description: Manages alternative programs for common commands\ndescription:\n    - Manages symbolic links using the 'update-alternatives' tool\n    - Useful when multiple programs are installed but provide similar functionality (e.g. different editors).\nversion_added: \"1.6\"\nauthor:\n    - \"David Wittman (@DavidWittman)\"\n    - \"Gabe Mulley (@mulby)\"\noptions:\n  name:\n    description:\n      - The generic name of the link.\n    required: true\n  path:\n    description:\n      - The path to the real executable that the link should point to.\n    required: true\n  link:\n    description:\n      - The path to the symbolic link that should point to the real executable.\n      - This option is required on RHEL-based distributions\n    required: false\n  priority:\n    description:\n      - The priority of the alternative\n    required: false\nrequirements: [ update-alternatives ]\n'''\n\nEXAMPLES = '''\n- name: correct java version selected\n  alternatives: name=java path=/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java\n\n- name: alternatives link created\n  alternatives: name=hadoop-conf link=/etc/hadoop/conf path=/etc/hadoop/conf.ansible\n\n- name: make java 32 bit an alternative with low priority\n  alternatives: name=java path=/usr/lib/jvm/java-7-openjdk-i386/jre/bin/java priority=-10\n'''\n\nimport re\nfrom ansible.module_utils.basic import *\nfrom ansible.module_utils.pycompat24 import get_exception\n\n\ndef main():\n\n    module = AnsibleModule(\n        argument_spec = dict(\n            name = dict(required=True),\n            path = dict(required=True, type='path'),\n            link = dict(required=False, type='path'),\n            priority = dict(required=False, type='int',\n                            default=50),\n        ),\n        supports_check_mode=True,\n    )\n\n    params = module.params\n    name = params['name']\n    path = params['path']\n    link = params['link']\n    priority = params['priority']\n\n    UPDATE_ALTERNATIVES = module.get_bin_path('update-alternatives',True)\n\n    current_path = None\n    all_alternatives = []\n\n    # Run `update-alternatives --display <name>` to find existing alternatives\n    (rc, display_output, _) = module.run_command(\n        ['env', 'LC_ALL=C', UPDATE_ALTERNATIVES, '--display', name]\n    )\n\n    if rc == 0:\n        # Alternatives already exist for this link group\n        # Parse the output to determine the current path of the symlink and\n        # available alternatives\n        current_path_regex = re.compile(r'^\\s*link currently points to (.*)$',\n                                        re.MULTILINE)\n        alternative_regex = re.compile(r'^(\\/.*)\\s-\\spriority', re.MULTILINE)\n\n        current_path = current_path_regex.search(display_output).group(1)\n        all_alternatives = alternative_regex.findall(display_output)\n\n        if not link:\n            # Read the current symlink target from `update-alternatives --query`\n            # in case we need to install the new alternative before setting it.\n            #\n            # This is only compatible on Debian-based systems, as the other\n            # alternatives don't have --query available\n            rc, query_output, _ = module.run_command(\n                ['env', 'LC_ALL=C', UPDATE_ALTERNATIVES, '--query', name]\n            )\n            if rc == 0:\n                for line in query_output.splitlines():\n                    if line.startswith('Link:'):\n                        link = line.split()[1]\n                        break\n\n    if current_path != path:\n        if module.check_mode:\n            module.exit_json(changed=True, current_path=current_path)\n        try:\n            # install the requested path if necessary\n            if path not in all_alternatives:\n                if not link:\n                    module.fail_json(msg=\"Needed to install the alternative, but unable to do so as we are missing the link\")\n\n                module.run_command(\n                    [UPDATE_ALTERNATIVES, '--install', link, name, path, str(priority)],\n                    check_rc=True\n                )\n\n            # select the requested path\n            module.run_command(\n                [UPDATE_ALTERNATIVES, '--set', name, path],\n                check_rc=True\n            )\n\n            module.exit_json(changed=True)\n        except subprocess.CalledProcessError:\n            e = get_exception()\n            module.fail_json(msg=str(dir(cpe)))\n    else:\n        module.exit_json(changed=False)\n\n\nmain()\n", "path": "system/alternatives.py"}]}