So we do have a bit of a strategic plan regarding modules to store inventory type information, in particular with fact caching, so I have preferences on where this goes.
Namely, I want things to record the package versions of all installed services and not have to rely on a register. Once this happens, something like this should be easily possible: package_information["httpd"]["version"] etc What you are asking to do regarding splitting things up, however, might be difficult -- if not everything follows that exact format. Something like a lookup plugin that uses Python's "LooseVersion" support to compare two different versions might be better than trying to split them out and do comparisons peacemeal. http://epydoc.sourceforge.net/stdlib/distutils.version.LooseVersion-class.html Hypothethically assume the following might exist: {{ version_compare(alpha, beta) }} which should return -1, 0, 1 depending on order. Perhaps this should be a Jinja2 filter, more like this: {{ alpha | version_compare(beta) }} In either case, the idea of sampling the installed versions seems to require fact caching (this release) to really be thought out correctly first, and I'd like to keep the numerical comparison filter/function seperate -- and I think that avoids the need to name each part of the version string. (This type of discussion is probably a better fit for ansible-devel, FWIW) On Tue, Dec 31, 2013 at 5:45 PM, Patrick Heeney <[email protected]>wrote: > I have been working with ansible for a few weeks now and I thought of a > useful module idea that I really am finding myself needing a lot. I am > posting here to open up a discussion in hopes of getting it implemented. I > don't know python at the moment so I am not in a position to implement > this. > > The goal of the module would be to parse version strings of different > services (maybe files?) and break them into usable chunks for conditionals. > I am finding myself needing this a lot since I need to put different > configuration files in place depending on what version is running. For > example if the playbook is running on ubuntu 10.04 I need mysql 5.1 > configuration entries whereas ubuntu 12.04 I need mysql 5.5. > > Here is some ideas of how it would look: > > - version: name=mysql > register: mysql_version > > - debug: var=mysql_version > > mysql_version: { > version: "5.5.34" > major: 5 > minor: 5 > patch: 34 > } > > Which would be parsed from: mysql -v: "Server version: > 5.5.34-0ubuntu0.12.04.1 (Ubuntu)" > > Another example: > > - version: name=apache2 > register: apache_version > > - debug: var=apache_version > > apache_version: { > version: "2.2.22" > major: 2 > minor: 2 > patch: 22 > } > > Which would be parsed from apache2 -v: "Server version: Apache/2.2.22 > (Ubuntu)" > > If the service is not running or not found it could just return blank. > > Right now I only need it for services. In order to implement it, it can > maybe regex search search > http://stackoverflow.com/questions/82064/a-regex-for-version-number-parsing?. > > It could potentially be expanded to search files such as: version: > path=/etc/lsb-release register: distro_version which would return version: > 12.04, major 12, minor 4, patch ''. Optionally it could have the regex as > an argument and perhaps a grep to narrow it down if the file has a lot of > numbers or different format: > > - version: path=/etc/lsb-release line=RELEASE > regexp='^(\d+\\.)?(\d+\\.)?(\\*|\d+)$' > > Which could parse cat /etc/lsb-release | grep RELEASE > > What do you think? > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- Michael DeHaan <[email protected]> CTO, AnsibleWorks, Inc. http://www.ansibleworks.com/ -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
