yum enablerepo won't do multiple repositories

Is anyone else having issues with the yum module’s enablerepo parameter? Suddenly I can’t enter multiple repositories. I am doing the following:

ansible server -s -K -m yum -a “name=package enablerepo=repo1,repo2 state=latest”

It consistently returns:

“msg”: “Error setting/accessing repo repo2: Error getting repository data for repo2, repository not found”

It is always the second repository that cannot be found (i.e. if I swap the order, then it will be repo1 that cannot be found). If I enable only one repository, then there is no issue. I am sure I have used this before, but now it does not work. I recently upgraded to 1.5.3 from 1.4.3, but I experienced the issue with both versions. I know that I was able to do this previously, perhaps in a version prior to 1.4.3
Thanks,
-Mark

I just tried this with the development version (1.6) and with 1.4.4 and all worked.

$ ansible server-01 -m yum -a ‘name=package enablerepo=repo1,repo2 state=latest’

So perhaps it has something to do with how I have my repositories configured. They look similar to the following:

repo1:
[repo1]
name=Repository 1
baseurl=http://repositoryserver/Repo1/$releasever/$basearch
gpgcheck=0
enabled=0

repo2:
[repo2]
name=Repository 2
baseurl=http://repositoryserver/Repo1/$releasever/$basearch
gpgcheck=0
enabled=0

The two repositories are intentionally kept disabled by default and are enabled as needed with the “enablerepo=” argument to yum. This works fine when I run yum manually, but fails when I try to run it with Ansible. If it is working for you, then I must be missing something. Any ideas?
Thanks,
-Mark

I tried disabling both of my repos and started it again and it still worked. Could you try running ansible with -vvvv?

I even went into the Python code and commented out the cleanup routines so that the tmp files would persist after execution (is there an easier way to do that?). When I looked into the Python yum file that was copied to the target, I found this:

MODULE_ARGS = ‘name=ansible enablerepo=uti_EPEL,ol6_latest state=latest’

So the arguments are being passed properly. But somewhere further on there is a disconnect in the interface to the actual yum command.

Below is what is output by ansible -vvv.
Thanks,
-Mark

ESTABLISH CONNECTION FOR USER: ansible on PORT 22 TO serv1
REMOTE_MODULE yum name=ansible enablerepo=uti_EPEL,ol6_latest state=latest
EXEC /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1398210973.51-184022099032293 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1398210973.51-184022099032293 && echo $HOME/.ansible/tmp/ansible-tmp-1398210973.51-184022099032293’
PUT /tmp/tmpC7FuQx TO /home/ansible/.ansible/tmp/ansible-tmp-1398210973.51-184022099032293/yum
EXEC /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=sbkgbcrmqwvqpushkumibwbbbcfwyqvd] password: " -u root /bin/sh -c '”’“‘echo SUDO-SUCCESS-sbkgbcrmqwvqpushkumibwbbbcfwyqvd; /usr/bin/python -tt /home/ansible/.ansible/tmp/ansible-tmp-1398210973.51-184022099032293/yum; rm -rf /home/ansible/.ansible/tmp/ansible-tmp-1398210973.51-184022099032293/ >/dev/null 2>&1’”‘"’’
serv1 | FAILED >> {
“failed”: true,
“msg”: “Error setting/accessing repo ol6_latest: Error getting repository data for ol6_latest, repository not found”

If I can see correctly you are using sudo, I wasn’t using sudo, maybe there is a problem with that?

Please make sure there is a github ticket if you would like us to investigate.

Thanks!

At this point, I am still trying to decide if I have found a real bug, or if I am just doing something stupid outside of Ansible. The yum module is fairly important and nobody else seems to be complaining about this, so I am leaning more towards my own configuration. I want to try to eliminate that before I make everyone jump through hoops to solve a problem that is specific to me, although it is a bit difficult to see what is happening down inside the code. There are a few other places I can look first (log files on the repository itself). If that doesn’t shed some light, then I guess I will have to reach out more.
Thanks,
-Mark

Okay, I am totally stymied. I could see no hits in the repository logs from my target server. I ran tcpdump to capture network on the target server to see if it might be reaching out to another repository in error, but the only traffic I saw was to the Ansible server, never to the repository. So from is appears that the yum module is simply not locating all of the repository information in the yum repository configuration files.
I guess I will have to open a ticket. I have not used GitHub before, so this will be a learning experience too.
-Mark

As mentioned above, it’s probably a glitch in some code that hasn’t been heavily utilized in a while.

Not too many people use the enablerepo parameter, and probably less with multiple-repos passed to the parameter, and the yum API, particularly when used with yum RHN plugin, occasionally has small differences between OS versions.

I saved the tmp file on a target server and looked through it to try to see what is happening. I was able to isolate the issue to this code snippet:

current_repos = my.repos.repos.keys()
for r in en_repos:
try:
my.repos.enableRepo(r)`
new_repos = my.repos.repos.keys()
for i in new_repos:
if not i in current_repos:
rid = my.repos.getRepo(i)
a = rid.repoXML.repoid
current_repos = new_repos
except yum.Errors.YumBaseError, e:
module.fail_json(msg=“Error setting/accessing repo %s: %s” % (r, e))

I added some print statements to output repo information as the code is executed:

current_repos = my.repos.repos.keys()
print (“current_repos = %s” % (current_repos))
for r in en_repos:
print (“checking repo %s against %s” % (r, current_repos))
try:
my.repos.enableRepo(r)
new_repos = my.repos.repos.keys()
print (“new_repos = %s” % (new_repos))
for i in new_repos:
print (“testing repo %s against %s” % (i, current_repos))
if not i in current_repos:
rid = my.repos.getRepo(i)
a = rid.repoXML.repoid
current_repos = new_repos
except yum.Errors.YumBaseError, e:
module.fail_json(msg=“Error setting/accessing repo %s: %s” % (r, e))

That generates this output:

current_repos = [‘ol6_latest’, ‘uti_EPEL’, ‘ol6_u4_base’]
checking repo: uti_EPEL against [‘ol6_latest’, ‘uti_EPEL’, ‘ol6_u4_base’]
new_repos = [‘uti_EPEL’]
testing repo uti_EPEL against [‘ol6_latest’, ‘uti_EPEL’, ‘ol6_u4_base’]
checking repo: ol6_latest against [‘uti_EPEL’]
{“msg”: “Error setting/accessing repo ol6_latest: Error getting repository data for ol6_latest, repository not found”, “failed”: true}

So, at the highlighted line, the list of repositories that the current repository is being tested against has been reduced to just the previously tested repository.
Now, I am not a Python programmer (I bought a “Learning Python” book a couple of months ago, but haven’t had time to go through it yet) and it was a stretch for me to get this far. I am not sure where to go from here, but hopefully someone more knowledgeable can look into it and carry the torch from here.
Thanks,
-Mark

Mark,

Thanks for digging into the issue. Would you mind updating the github ticket with this new information?

Thanks!

James

Done! Except I see that the test formatting (bold) didn’t carry across. But I think there is still enough information there that someone can figure out what i meant.
Thanks,
Mark