Skip to content
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

Ansible-lint warn [301] Commands should not change things if nothing needs doing #144

Closed
edouard-lopez opened this issue Feb 9, 2021 · 2 comments

Comments

@edouard-lopez
Copy link

I have a task:

- name: Create Certificate for webapps
  command: "{{ certbot_create_command }}"
  notify: Reload Apache
  tags: [web, ssl]

But ansible-lint complains

  WARNING  Listing 1 violation(s) that are fatal                                                                                                                                                                                         
  [301] Commands should not change things if nothing needs doing

What conditional do you recommend?`

@Mystic8b
Copy link

Mystic8b commented May 9, 2021

Hey! You just need to add this:
changed_when: false

@olof-j
Copy link

olof-j commented Dec 15, 2022

Just for context: doing changed_when: false will make a task show as unchanged, even though it has caused changes. To me, accepting a false positive (a noop command showing up as changed) would be better than a false negative (a command that makes changes shows up as ok). Especially in situations like this, that deal with creating certificates. A reasonable condition would be: does the certificate file exists?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants