Found bug in "apt_rpm" module, fixed it. Not sure how to help.

158 views
Skip to first unread message

Peter Rupp

unread,
Jan 8, 2017, 2:08:07 PM1/8/17
to Ansible Project
Hello, this is my first post to the ansible community.
I'm a newby to Ansible, but a very experienced python developer.
Anyway, after installing the latest Ansible 2.2.2.0, I tried out a simple module call to verify if a RPM package existed on some RHEL 6/7 systems.    Anyway, the module failed, with the error:

        "cannot find /usr/bin/apt-get and/or /usr/bin/rpm"

My first curiosity was to figure out what python module they used to execute "rpm" or "apt-get", and see what path it used (if any) and how to correct.    Somebody else had a similar problem, and the answers coming back were focusing on the user's PATH or SUDO configuration, but there was never a resolution. 


Anyway, I , decided to take a look at "apt_rpm.py" directly, and lo and behold, I think I found the problem.   In the very beginning of the "main()" function, the author tries determine if either "apt-get" or "rpm" are available...and if so continue on, or FAIL if not.  Makes sense?  However,  way the if conditional was written is kind of confusing, and I believe it exits with a FAIL if only the 'apt-get' is missing, which I encounter on a RHEL system.   To make a long story short, I rewrote the if conditional to be a little clearer, and IT WORKS!. 

Here's what I did:


Replace:

   
    153     if not os.path.exists(APT_PATH) or not os.path.exists(RPM_PATH):
    154         module.fail_json(msg="cannot find /usr/bin/apt-get and/or /usr/bin/rpm")

With...
    153     if (os.path.exists(APT_PATH) or os.path.exists(RPM_PATH)):
    154         pass
    155     else:
    156         module.fail_json(msg="cannot find /usr/bin/apt-get and/or /usr/bin/rpm")  




I believe this bug has existed from v1.5, and kind of surprised it hasn't been found.
Let me know how I can either:
1.   Who or how should I get this to an existing Ansible developer to look at?
2.   Please direct me to how I can become an ansible developer and start writing high-quality code to help you'alls out.  :-)

Thank You
Peter

 

Brian Coca

unread,
Jan 9, 2017, 1:20:47 PM1/9/17
to ansible...@googlegroups.com
Hi,


​To start contributing you can just create a pull request against our github repo : https://github.com/ansible/ansible

I recommend reading through developer information docs http://docs.ansible.com/ansible/dev_guide/index.html


​As for why it fails, it might be because the author assumes you need both tools to handle the transformations (I'm not sure I have not checked the module's code).​


----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages