geerlingguy/ansible-role-certbot

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

edouard-lopez opened this issue ยท 2 comments

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?`

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

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?