-
-
Notifications
You must be signed in to change notification settings - Fork 645
Require minimum version of Ansible #908
Comments
I think I may spend some time later turning this into a module, but here's a python script that will fail if the installed version of Ansible isn't at least 2.1.0: # -*- encoding:utf-8 -*-
from distutils.version import LooseVersion
import sys
import ansible
def print_red_bold(text):
print('\x1b[31;1m' + text + '\x1b[0m')
def __init__(self):
# Can't use `on_X` because this isn't forwards compatible with Ansible 2.0+
required_version = '2.1.0'
installed_version = ansible.__version__
if LooseVersion(installed_version) < LooseVersion(required_version):
print_red_bold(
"drupal-vm restriction: only Ansible version greater than {version} is supported.\n"
.format(version=required_version)
)
sys.exit(1) |
For easier maintenance (e.g. when 2.2+ comes out), to test a minimum version, we can use version_compare... I hope :) |
Nice... looks like there's already a globally-accessible Test playbook:
Output:
|
I'll be adding a new variable for this and for vagrant min version (was going to hardcode it in playbook, but it's nicer to use a var): drupalvm_vagrant_version_min: '1.8.5'
drupalvm_ansible_version_min: '2.1' |
@geerlingguy nice catch. I looked for both a version_compare function and an ansible_version var and couldn't find either. ansible_version wasn't listed when I ran setup ad-hoc |
One thing to note is that if someone has a really old version of Ansible, it's likely to fail on a syntax check before it ever gets to running your version check task. The only way I know to get around this is to write something as a callback module that is compatible with both pre and post 2.0 |
@smiller171 - True, mentioned in blog post here: http://www.jeffgeerling.com/blog/2016/require-minimum-ansible-version-your-playbook I'd rather Ansible solves this upstream... everyone adding their own callback plugin for a version check seems a bit crazy. |
Agreed. I wonder if Ansible would accept a pull request to add in that functionality. Having it as a top-level parameter for a play seems to make sense: - hosts: all
minimum_ansible_version: 1.9.2
tasks:
..... Of course this isn't helpful for users of old versions, since the old versions wouldn't support the |
It would be great if Drupal VM asserted that a minimum version of Ansible is in use.
You could use the assert module for this.
Something like:
The text was updated successfully, but these errors were encountered: