Unsupported parameters for (copy) module: when

I’ve got a task I’m trying to run, where a file gets copied if that file has changed. It’s a local file (though it’s copied from a remote to a local destination first) and I want to copy it to several hosts. When I run the task it bombs with

Unsupported parameters for (copy) module: when. Supported parameters include: attributes,backup,content,delimiter,dest,directory_mode,follow,force,group,mode,original_basename,owner,regexp,remote_src,selevel,serole,setype,seuser,src,unsafe_writes,validate

Here’s the part of the play that’s relevant:

tasks:

  • name: get stat of files
    stat:
    path: files/WHITELIST-squash.txt
    register: whitelist

  • name: Push to mail proxies
    copy:
    src: files/WHITELIST-squash.txt
    dest: /root/bin/postfixFindSpammers.ignore
    backup: yes
    when: whitelist.stat.changed

The problem is, when I’ve googled the copy module, other sources are saying ‘when’ can be used with it. The documentation doesn’t, so what’s the bloody deal here? Can or can you not use when with copy? To me, this seems silly to have that option. I’ve noticed that you can use when with a template, which is nothing but a copy with some dynamic editing thrown in.

I don’t get it. Any ideas?

Your indentation is a little off:

      - name: Push to mail proxies
        copy:
         src: files/WHITELIST-squash.txt
         dest: /root/bin/postfixFindSpammers.ignore
         backup: yes
         when: whitelist.stat.changed

`when:` is *below* `copy:`, so it's passed to the copy module instead of
being processed by Ansible itself (like the `register:` you're already
using correctly).
Bring it to the same indentation level as your module invocation instead:

      - name: Push to mail proxies
        copy:
         src: files/WHITELIST-squash.txt
         dest: /root/bin/postfixFindSpammers.ignore
         backup: yes
        when: whitelist.stat.changed

Best,
Nils

It's funny, I tried that and it gave me the same error. Oh well. I found a way around the problem, sometimes the Jeremy Clarkson hammer method is best.

Thanks for the help.

Mixed tabs and spaces perhaps?
And saying "below" might have been a bit ambiguous: it's all about the
indentation; ordering doesn't matter.

Best,
Nils

I'm aware of that. And my syntax check cleared fine. Sublime 3 has a great YAML syntax highlighter, and I made sure backspace to the beginning of the line and space over, because I'm so used to TAB indentation that I've borked files several times. Maybe I missed something like that, but it's moot now, I threw a nuke at it instead of a hand grenade to get it done and working.