cis-ubuntu-ansible
cis-ubuntu-ansible copied to clipboard
Deprecation warnings
use check_mode instead of always_run because of deprecation
Any clue why Travis is showing the following error?
ERROR: check_mode is not a legal parameter in an Ansible task or handler
I think it was added in Ansible 2.2. If we use that, we'll have to drop support for 1.9 and 2.0.
@pchaigno, can you think of a fancy way to support all versions?
This is the same issue as #122. I hit it when moving to 2.1 or 2.2. I don't know of a good way to support all versions.
I tried a couple of things that did not work:
#!/usr/bin/env ansible-playbook
---
- name: Test always run / check_mode
hosts: localhost
tasks:
- name: Test false 1
command: /bin/false
register: false_result
changed_when: false_result.rc == 0
failed_when: false_result.rc != 0 and false_result.rc != 1
always_run: True
when: "{{ ansible_version < 2.2 }}"
- name: Test false 2
command: /bin/false
register: false_result
changed_when: false_result.rc == 0
failed_when: false_result.rc != 0 and false_result.rc != 1
check_mode: no
when: "{{ ansible_version > 2.1 }}"
- name: Test false 3
command: /bin/false
register: false_result
changed_when: false_result.rc == 0
failed_when: false_result.rc != 0 and false_result.rc != 1
check_mode: no '{{ (ansible_version > 2.1) | ternary("value",omit) }}'
always_run: True '{{ (ansible_version < 2.2) | ternary("value",omit) }}'
result with ansible 2.2.0.0:
PLAY [Test always run / check_mode] ********************************************
TASK [setup] *******************************************************************
Friday 10 March 2017 11:37:09 +1300 (0:00:00.019) 0:00:00.019 **********
ok: [localhost]
TASK [Test false 1] ************************************************************
Friday 10 March 2017 11:37:12 +1300 (0:00:03.277) 0:00:03.297 **********
[DEPRECATION WARNING]: always_run is deprecated. Use check_mode = no instead..
This feature will be removed in version 2.4. Deprecation warnings can be disabled by setting deprecation_warnings=False in
ansible.cfg.
skipping: [localhost]
TASK [Test false 2] ************************************************************
Friday 10 March 2017 11:37:13 +1300 (0:00:00.032) 0:00:03.329 **********
ok: [localhost]
TASK [Test false 3] ************************************************************
Friday 10 March 2017 11:37:13 +1300 (0:00:00.206) 0:00:03.536 **********
[DEPRECATION WARNING]: always_run is deprecated. Use check_mode = no instead..
This feature will be removed in version 2.4. Deprecation warnings can be disabled by setting deprecation_warnings=False in
ansible.cfg.
ok: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
We could probably write our own module to backport check_mode
to Ansible < 2.2.0, but I doubt it's worth it. Ansible 2.2.0 is still pretty new (end of 2016), so maybe we should wait 2.3.0 before dropping support for Ansible < 2.2.0?
I concur. @donovan, do you think it's OK to wait until 2.3.0 to move towards check_mode
?
Should be OK yes, people who have already moved to 2.2 can do what I did and patch their local copy if they want to get rid of the warnings.
Ansible 2.4 is out, we really need to revisit this.
@donovan Could you update your branch to remove Ansible 2.0 and 1.9.1 from the .travis.yml
file and add Ansible 2.1, 2.2, 2.3, and 2.4?