Hello,
I am a perfectionist. I want write ansible-playbooks that have backward compatibility.
For example if I use ansible < 1.5.1 http://docs.ansible.com/ansible/get_url_module.html I use it without validate_certs but in newer versions I must use with validate_certs=no.
But in ansible < 1.4 there wasn’t this option it was failed because “no module option”.
Also I wasn’t able to find how to detect an ansible version. I wanted to do something like this:
`
- name: Include task based on the OS enviroment
include: “{{item}}”
with_first_found:
|
|
or
`
- name: Include task based on the ansible version
include: “{{ ansible_os_family }}-ansible-{{ ansible_major_version }}.yml”
`
But ansible said that it’s deprecated behavior.
I detected ansible version simply in the playbook, but it’s not good (I think):
`
-
name: Detect ansible major version
shell: ansible-playbook --version 2> /dev/null|cut -d " " -f2|cut -d “.” -f1
register: ansible_version_check
ignore_errors: True -
name: Setting ansible major version variable
set_fact:
ansible_curr_major_version: “{{ ansible_version_check[‘stdout’] }}” -
name: Setting ansible major version variable
set_fact:
ansible_major_version: “{{ ansible_version_check[‘stdout’] }}” -
name: Setting ansible version variable
set_fact:
ansible_curr_full_version: “{{ ansible_version_check[‘stdout’] }}”
`
I found more simply way through an enviroment variable:
ANSIBLE_SHORT_VERSION=
ansible-playbook --version 2> /dev/null|cut -d " " -f2|cut -d “.” -f1,2` ansible-playbook -i …
`
and in the defaults/main.yml:
`
ansible_curr_short_version: “{{ lookup(‘env’,‘ANSIBLE_SHORT_VERSION’)| default(‘1.5’) }}”
old_ansible_versions: [‘1.4’,‘1.3’, ‘1.2’, ‘1.1’,‘1.0’]
`
in the tasks I use /tasks/main.yml:
`
- include: old.yml
when: “ansible_curr_short_version in old_ansible_versions”
`
PS:
If there is possibility to use modules that added new option’s in the old version of ansible? Ignore them?