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

89 views
Skip to first unread message

Mark

unread,
May 14, 2015, 6:53:35 PM5/14/15
to ansible...@googlegroups.com
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.

Brian Coca

unread,
May 15, 2015, 9:39:09 AM5/15/15
to ansible...@googlegroups.com
I would switch to the template module, copy's content is not a good
method for anything but trivial file content.




--
Brian Coca

Mark

unread,
May 18, 2015, 3:27:24 PM5/18/15
to ansible...@googlegroups.com
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...?

Mark

unread,
May 18, 2015, 3:29:19 PM5/18/15
to ansible...@googlegroups.com
Ideally, something like

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

Brian Coca

unread,
May 18, 2015, 4:03:01 PM5/18/15
to ansible...@googlegroups.com
templates should get all current variables by default

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



--
Brian Coca
Reply all
Reply to author
Forward
0 new messages