Hi,
I can’t write a syntactically correct playbook. How it would be right to write following command:
- name: test escaping
command: mycommand subcommand --option=‘{“first-item”: 2}’
Can you give me advice?
Hi,
I can’t write a syntactically correct playbook. How it would be right to write following command:
command: mycommand subcommand --option=‘{“first-item”: 2}’
Can you give me advice?
First, ansible version and error output would be helpful, but taking a
guess try this:
- name: test escaping
command: "mycommand subcommand --option={'first-item': 2}' "
Yep.
When you encounter problems it is always suggested to paste whatever error you had.
I’m guessing this is just the common “if you start a line or end a line with a quote, the whole thing must be quoted” which is one of the two gotchas on http://ansibleworks.com/docs/YAMLSyntax.html
Ansible in version 1.4 or later will share some syntax tips, but in either case the exception should indicate you had a YAML syntax error.
I’m sorry for not including debug output, I saw this error so many times that already thought that it’s pretty common. Ansible version is 1.3.3.
The error was:
ERROR: Syntax Error while loading YAML script, playbook.yml
Note: The error may actually appear before this position: line 53, column 77
This actually shows that I have problems not with quotes and braces, but with colon. It’s one of number of non-working examples. It was solved by embracing colon with single quotes.
And working solution is:
I removed space after colon, and removed single quotes, but I want solution that includes them, so I’m consider question is still open.
This is the "you have a free colon in your output, you must quote the whole line, thing.
So basically what Brian suggested above will take care of it.
Well, in that case I have syntactically correct YAML, but because Brian omitted outer single-quotes, it performs a wrong command. Verbose output:
changed: [192.168.1.107] =>
{“changed”: true,
“cmd”: [“mycommand”, “subcommand”, “–option={first-item:”, “2}”],
“delta”: “0:00:00.162754”,
“end”: “2013-11-02 15:08:57.654332”,
“rc”: 0, “start”: “2013-11-02 15:08:57.491578”,
“stderr”: “upload: invalid arguments”,
“stdout”: “mycommand subcommand[OPTIONS]\n --help display help”}
If I insert the outer quotes, the following error will appear:
ERROR: Syntax Error while loading YAML script, playbook.yml
Note: The error may actually appear before this position: line 53, column 73
^
Anyway, if I’ve missing something, this “something” is definetely about YAML syntax and not about Ansible and I should ask it somewhere else. Especially that my problem is already solved in other way.
Thanks.
Try using YAML “>” quoting mechanism. This causes the block following the “>” to be interpreted as a YAML scalar, and hence, ignores other YAML special characters like "{ " and ": "
When you said you inserted outer quotes, the example you showed did not show any outer quotes at all.
I mean quote the entire value.
Alternatively, see what Kahil wrote.
Hi, trying to execute task:
Ansible dislikes “:”
with_items:
Should be written as:
with_items:
Hi,
Alternatively you can use the “> notation” :
shell: >
curl -X POST http://{{ influxdb.host }}:{{ influxdb_client_port }}/db?u=root&p=root -d “{‘name’: ‘spark-metrics’}”
Cheers
Ulli
Here is working solution
- name: Create spark-metrics DB
uri:
url: "http://{{ influxdb.host }}:{{ influxdb_client_port }}/db?u=root&p=root"
method: POST
body: "{\"name\": \"spark-metrics\"}"
status_code: 201