Having problems with --exclude, --include with synchronize module using rsync_opts

Hi,

I was trying to do something using synchronize where I exclude some files and include others, but it does not work like rsync:

So, this works with rsync,

  • name: testrsync
    local_action: command rsync -aH --include ‘[e|p]’ --exclude '’ prmfiles/output/{{ item.key }}/ {{ ansible_user_id }}@{{ inventory_hostname }}:/export/home/oracle/hhenjum/heathtest/
    when: oggaction == “prmfiles”
    with_dict: dirprm | default({})

But, when I try to do this with synchronize, I can’t get it to work. It just passes through saying the step is “ok”… or no changes to do.

  • name: testsync
    synchronize: src=prmfiles/output/{{ item.key }}/ dest=/export/home/oracle/hhenjum/heathtest/ checksum=yes rsync_opts=“rsync_opts=–include=‘e*’, --exclude=‘*’”
    when: oggaction == “prmfiles”
    with_dict: dirprm | default({})

If I don’t have the double quotes around rsync_opts, then it gives me, msg: unsupported parameter for module: --exclude

I imagine this is something with the wildcards? Also, I understand it probably wasn’t the intention for rsync_opts to handle everything you can do with rsync.

It’s not a huge issue. I just changed the deploy so that we can just sync the whole directory rather than specific files, but I thought I’d check in case it should work.

Thanks,
Heath

We are also having some problems at the day job with wild cards and the synchronize module however ours is tied to the src argument.

htttps://github.com/ansible/ansible/issues/7728

I've been looking when I have a chance but haven't figured out what's going wrong. I just know the command Ansible is reporting it runs works fine on the command line. Remove the wildcard and Ansible runs. Put it back in and it fails.

<tim/>

Don’t know, any debugging would be appreciated.

I found what the problem is though I don’t know what the right solution is.

https://github.com/ansible/ansible/pull/7820

Essentially safe shell module causes wildcards to be treated as literals with rsync. As long as that is the case you can’t use wildcards with sync module, but you can’t do that either as stated in the pull request comments so I’m at a bit of a loss how to resolve this issue.

I read the description from pull 7820, and it makes sense. For my situation, I’m pretty sure with_fileglob would work, but I haven’t tested it.

Thanks Tim for finding the issue.