-
Notifications
You must be signed in to change notification settings - Fork 654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditions are not respected when inspecting tasks in a block #1894
Comments
AFAIK you must use |
I don't think this has anything to do with ---
- name: Check ccache version
command: "ccache --version"
environment:
PATH: "{{ ccache_install_prefix }}/bin:{{ ansible_pkg_mgr_path }}"
changed_when: false
failed_when: false
register: ccache_version_cmd
- name: Run configure script
command: "./configure --prefix={{ ccache_install_prefix }}"
args:
chdir: "{{ ccache_build_dir }}/ccache-{{ ccache_version }}"
when: >
ccache_version_cmd.rc != 0 or
ccache_version not in ccache_version_cmd.stdout_lines[0]
- name: Build ccache
command: "make -j{{ ccache_make_jobs }}"
args:
chdir: "{{ ccache_build_dir }}/ccache-{{ ccache_version }}"
when: >
ccache_version_cmd.rc != 0 or
ccache_version not in ccache_version_cmd.stdout_lines[0]
- name: Install ccache
become: true
command: "make install"
args:
chdir: "{{ ccache_build_dir }}/ccache-{{ ccache_version }}"
when: >
ccache_version_cmd.rc != 0 or
ccache_version not in ccache_version_cmd.stdout_lines[0] But, placing the last three tasks in a
See also: https://everythingshouldbevirtual.com/automation/Ansible-Blocks-With-Conditionals/ |
@cognifloyd Do you think you could add a fix for this one? It is a side effect of #1809 and I suspect we need to inherit stuff like In fact I think that the same issue prevents collection name resolution from working like when you define |
Fascinating. I suppose that makes sense. Normalizing like that has implications for the future transforms feature as well. To be able to fix conditions they would need the whole file instead of just the target task. I probably won't get to this today, but I do want to fix this. |
Unable to reproduce with current versions. |
@ssbarnea Sorry, but the issue is still reproducible with ansible-ilnt 6.8.0b1. |
@ssbarnea Did you see my above comment? This issue is still present in 6.8.2 and can be reproduced with the example code in the issue description. |
Summary
In #1809 (part of version 5.4.0), ansible-lint gained the ability to inspect tasks inside of a
block
. However, it doesn't look at the block's conditions when inspecting the task, which results in erroneousno-changed-when
errors.Issue Type
Ansible and Ansible Lint details
OS / ENVIRONMENT
Ubuntu Linux 20.04
STEPS TO REPRODUCE
For an example, see the
build-sources.yml
task file of theableton.ccache
role here. An abbreviated version of this file follows:In a
block
, conditions are applied to each task implicitly. But for the above code, ansible-lint emits ano-changed-when
violation because it doesn't realize that thecommand
tasks actually do have a condition attached to them.Desired Behavior
no-changed-when
shouldn't be raised when tasks are inside of ablock
, and thatblock
has awhen
condition.The text was updated successfully, but these errors were encountered: