cis-ubuntu-ansible icon indicating copy to clipboard operation
cis-ubuntu-ansible copied to clipboard

Deprecation warnings

Open davidpanofsky opened this issue 8 years ago • 9 comments

use check_mode instead of always_run because of deprecation

davidpanofsky avatar Jan 23 '17 21:01 davidpanofsky

Any clue why Travis is showing the following error?

ERROR: check_mode is not a legal parameter in an Ansible task or handler

awailly avatar Mar 09 '17 20:03 awailly

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 avatar Mar 09 '17 20:03 pchaigno

@pchaigno, can you think of a fancy way to support all versions?

awailly avatar Mar 09 '17 20:03 awailly

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.

donovan avatar Mar 09 '17 21:03 donovan

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

donovan avatar Mar 09 '17 22:03 donovan

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?

pchaigno avatar Mar 10 '17 05:03 pchaigno

I concur. @donovan, do you think it's OK to wait until 2.3.0 to move towards check_mode ?

awailly avatar Mar 10 '17 17:03 awailly

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.

donovan avatar Mar 10 '17 20:03 donovan

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?

pchaigno avatar Oct 03 '17 09:10 pchaigno