Repository: ansible/ansible-modules-extras

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



Discussion:
cc: @DavidWittman @mulby

[module: system/alternatives.py]

Hi @zlalanne -- Thanks for submitting this feature idea. It looks like @gregdek did some pinging back in June -- he and I are currently going through and triaging outstanding issues in extras, so I'm just going to put some extra context in here for anyone who may see this in the future, and to re-ping the module owners just in case they have a moment of inspiration :)

@DavidWittman & @mulby -- Pinging you to bring this feature request for your attention. Please note that you are under no particular obligation to add this feature.

We encourage all Ansible community members to submit pull requests to satisfy feature requests. Consult the module guidelines (http://docs.ansible.com/ansible/developing_modules.html) for more information.


Resolving patch:
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 @@ def main():
             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 @@ def main():
     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 @@ def main():
                     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
                 )
 


Test patch: