Copy task w/Content being evaluated as parameters and causing it to fail

I’m trying to capture the contents of a variable that was registered from a previous task, and write it to file for later debugging / troubleshooting if the need arises.

The variable essentially has this in it:

{“changed”: true, “cmd”: [“mongo”, “–eval”, “printjson(rs.add("myserver"))”], “delta”: “0:00:00.130748”, “end”: “2015-05-14 22:43:14.453176”, “rc”: 0, “start”: “2015-05-14 22:43:14.322428”, “stderr”: “”, “stdout”: “MongoDB shell version: 3.0.3\nconnecting to: test\n{\n\t"ok" : 0,\n\t"errmsg" : "Found two member configurations with same host field, members.1.host == members.3.host == myserver",\n\t"code" : 103\n}”, “warnings”: }

I then want to record it, possibly to another server…

  • copy: content=“‘{{ theVariable }}’” dest=/somefile-{{ ansible_fqdn }}.json

delegate_to: masterServer

Ansible fails with the following error:

fatal: a duplicate parameter was found in the argument string ()

I’ve observed this (or something similar) a couple of times when using the “content” parameter with copy.

Is there a way to get copy w/ content + variables to work…? Aside from using shell and | tee the results… but there’s been a few cases where this functionality would have been helpful.

Thanks.

I would switch to the template module, copy's content is not a good
method for anything but trivial file content.

Brain - trying to capture output of an ansible command. Can’t use a template in that situation unless there’s some way it can pull in runtime variables…?

Ideally, something like

  • copy var_content=myVariable dest=/tmp/myFile.json

templates should get all current variables by default