Repository: ansible/ansible

Issue:
Allow to use '*test*' in enablerepo for yum action
Yum commandline permit to use a wildcard to enable and disable
repositories in the --enablerepo switch, permitting to enable
a complete set of repository at once ( like all rpmfusion, all
update-testing, etc ).

However, this doesn't work in yum due to more stringent checks
that verify that a exact match is given for the name of the
repository , see commit 5c26805.

This commit enhance the check by permitting to test more than
1 repository at a time, thus permitting to use wildcards.



Discussion:
This looks good, just for sanity check purposes, can you share which OSes you have tested this on?

We'll do some checking also.

I only tested on fedora 19, but I can do some check on rhel 6 and older fedora. I am just concerned about rhel 5 and python 2.4, since it doesn't have the set builtin ( only python 2.6 ).

Yes, this needs to run on EL5 managed machines.   I'd suggest implementing
this with a hash table to get the set behavior and then just do a .keys()
on it.

On Sat, Aug 17, 2013 at 10:45 AM, mscherer notifications@github.com wrote:

> I only tested on fedora 19, but I can do some check on rhel 6 and older
> fedora. I am just concerned about rhel 5 and python 2.4, since it doesn't
> have the set builtin ( only python 2.6 ).
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/ansible/ansible/pull/3873#issuecomment-22813041
> .

So, I did rewrote the code without set, but as I am unable to find a RHEL 5 where I am root, i just did the test on a fedora 19, but i guess it should run fine.

Tested fine on RHEL 5.8:

<pre>
$ ansible-playbook -i 192.168.122.100, ~/test_yum_repo_wildcard.yml 
PLAY [all] ******************************************************************** 
TASK: [yum name=drupal7-7.23] ************************************************* 
failed: [192.168.122.100] => {"changed": false, "failed": true, "rc": 0, "results": []}
msg: No Package matching 'drupal7-7.23' found available, installed or updated
...ignoring
TASK: [yum name=drupal7-7.23 enablerepo="*test*"] ***************************** 
changed: [192.168.122.100]
PLAY RECAP ******************************************************************** 
192.168.122.100            : ok=2    changed=1    unreachable=0    failed=0   
</pre>

Merged, thanks!


Resolving patch:
diff --git a/lib/ansible/modules/cloud/linode/linode.py b/lib/ansible/modules/cloud/linode/linode.py
--- a/lib/ansible/modules/cloud/linode/linode.py
+++ b/lib/ansible/modules/cloud/linode/linode.py
@@ -371,7 +371,7 @@ def linodeServers(module, api, state, name, alert_bwin_enabled, alert_bwin_thres
         if not servers:
             for arg in (name, plan, distribution, datacenter):
                 if not arg:
-                    module.fail_json(msg='%s is required for active state' % arg)
+                    module.fail_json(msg='%s is required for %s state' % (arg, state))
             # Create linode entity
             new_server = True
 
@@ -407,7 +407,7 @@ def linodeServers(module, api, state, name, alert_bwin_enabled, alert_bwin_thres
         if not disks:
             for arg in (name, linode_id, distribution):
                 if not arg:
-                    module.fail_json(msg='%s is required for active state' % arg)
+                    module.fail_json(msg='%s is required for %s state' % (arg, state))
             # Create disks (1 from distrib, 1 for SWAP)
             new_server = True
             try:
@@ -423,11 +423,14 @@ def linodeServers(module, api, state, name, alert_bwin_enabled, alert_bwin_thres
                     res = api.linode_disk_createfromdistribution(
                         LinodeId=linode_id, DistributionID=distribution,
                         rootPass=password, rootSSHKey=ssh_pub_key,
-                        Label='%s data disk (lid: %s)' % (name, linode_id), Size=size)
+                        Label='%s data disk (lid: %s)' % (name, linode_id),
+                        Size=size)
                 else:
                     res = api.linode_disk_createfromdistribution(
-                        LinodeId=linode_id, DistributionID=distribution, rootPass=password,
-                        Label='%s data disk (lid: %s)' % (name, linode_id), Size=size)
+                        LinodeId=linode_id, DistributionID=distribution,
+                        rootPass=password,
+                        Label='%s data disk (lid: %s)' % (name, linode_id),
+                        Size=size)
                 jobs.append(res['JobID'])
                 # Create SWAP disk
                 res = api.linode_disk_create(LinodeId=linode_id, Type='swap',
@@ -449,7 +452,7 @@ def linodeServers(module, api, state, name, alert_bwin_enabled, alert_bwin_thres
         if not configs:
             for arg in (name, linode_id, distribution):
                 if not arg:
-                    module.fail_json(msg='%s is required for active state' % arg)
+                    module.fail_json(msg='%s is required for %s state' % (arg, state))
 
             # Check architecture
             for distrib in api.avail_distributions():
@@ -535,12 +538,11 @@ def linodeServers(module, api, state, name, alert_bwin_enabled, alert_bwin_thres
             instances.append(instance)
 
     elif state in ('stopped'):
-        for arg in (name, linode_id):
-            if not arg:
-                module.fail_json(msg='%s is required for active state' % arg)
+        if not linode_id:
+            module.fail_json(msg='linode_id is required for stopped state')
 
         if not servers:
-            module.fail_json(msg = 'Server %s (lid: %s) not found' % (name, linode_id))
+            module.fail_json(msg = 'Server (lid: %s) not found' % (linode_id))
 
         for server in servers:
             instance = getInstanceDetails(api, server)
@@ -556,12 +558,11 @@ def linodeServers(module, api, state, name, alert_bwin_enabled, alert_bwin_thres
             instances.append(instance)
 
     elif state in ('restarted'):
-        for arg in (name, linode_id):
-            if not arg:
-                module.fail_json(msg='%s is required for active state' % arg)
+        if not linode_id:
+            module.fail_json(msg='linode_id is required for restarted state')
 
         if not servers:
-            module.fail_json(msg = 'Server %s (lid: %s) not found' % (name, linode_id))
+            module.fail_json(msg = 'Server (lid: %s) not found' % (linode_id))
 
         for server in servers:
             instance = getInstanceDetails(api, server)
@@ -587,6 +588,7 @@ def linodeServers(module, api, state, name, alert_bwin_enabled, alert_bwin_thres
     # Ease parsing if only 1 instance
     if len(instances) == 1:
         module.exit_json(changed=changed, instance=instances[0])
+
     module.exit_json(changed=changed, instances=instances)
 
 def main():


Test patch: