Reputation: 5857
I'm developing a playbook to maintain a Kubernetes cluster. There is a command I have to execute to add an entry in etcd:
- command: etcdctl mk /kube-centos/network/config "{ \"Network\": \"172.30.0.0/16\", \"SubnetLen\": 24, \"Backend\": { \"Type\": \"vxlan\" } }"
When trying to execute, Ansible gives a syntax error on the first colon:
- command: etcdctl mk /kube-centos/network/config '{ "Network": "172.30.0.0/16", "SubnetLen": 24, "Backend": { "Type": "vxlan" } }'
^ here
I can't figure out how to escape these characters. What is the best way to pass a JSON argument to a command like this?
There are actually two ways to fix this:
Answer 1
Surround the entire command in single quotes:
- command: 'etcdctl mk /kube-centos/network/config "{ \"Network\": \"172.30.0.0/16\", \"SubnetLen\": 24, \"Backend\": { \"Type\": \"vxlan\" } }"'
Answer 2 (Preferred)
Surround all colons in double quotes:
- command: etcdctl mk /kube-centos/network/config "{ \"Network\"":" \"172.30.0.0/16\", \"SubnetLen\"":" 24, \"Backend\"":" { \"Type\"":" \"vxlan\" } }"
Upvotes: 2
Views: 2580
Reputation: 52423
Easiest way is to enclose the colon in double quotes. Works always.
- command: etcdctl mk /kube-centos/network/config "{ \"Network\"":" \"172.30.0.0/16\", \"SubnetLen\"":" 24, \"Backend\"":" { \"Type\"":" \"vxlan\" } }"
Upvotes: 1
Reputation: 3215
check this
you need to quote the whole thing like this:
- command: 'echo "semicolon is: bad"'
cause ansible does not like semicolons much.
Upvotes: 0