Unsupported parameters for (copy) module: when

1,839 views
Skip to first unread message

mark....@neonova.net

unread,
Jul 31, 2017, 1:26:03 PM7/31/17
to Ansible Project
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?

Nils Steinger

unread,
Jul 31, 2017, 1:53:17 PM7/31/17
to ansible...@googlegroups.com
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


Mark Haney

unread,
Jul 31, 2017, 1:57:48 PM7/31/17
to ansible...@googlegroups.com
On 07/31/2017 01:50 PM, Nils Steinger wrote:
> 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:
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.


--

Mark Haney
Network Engineer at NeoNova
919-460-3330 option 1
mark....@neonova.net
www.neonova.net

Nils Steinger

unread,
Jul 31, 2017, 2:05:41 PM7/31/17
to ansible...@googlegroups.com
On 2017-07-31 19:57, Mark Haney wrote:
> 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.

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

Mark Haney

unread,
Jul 31, 2017, 2:12:09 PM7/31/17
to ansible...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages