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?