如何让clojure生成这个简单的YAML文件?

时间:2019-01-23 01:45:51

标签: clojure ansible yaml

我希望clojure生成此简单的Ansible YAML文件:

- hosts: 172.16.10.104 
  tasks: 
    - name: ping
      ping: 

我使用https://github.com/owainlewis/yaml生成它:

 (def data [{:hosts "172.16.10.104"}
         {:tasks [{
                   :name "ping",
                   :ping ""
                   }]}
         ])

得到了:

- hosts: 172.16.10.104
- tasks:
    - name: ping
      ping: ''

我想要“任务”而不是“-任务”,如何解决?

1 个答案:

答案 0 :(得分:3)

如果您按以下方式组织数据,

(def data [{:host  "172.16.10.104"
            :tasks [{:name "ping" :ping ""}]}])

然后

(yaml/generate-string data :dumper-options {:flow-style :block})

收益

"- host: 172.16.10.104\n  tasks:\n  - name: ping\n    ping: ''\n"

其格式为:

- host: 172.16.10.104
  tasks:
  - name: ping
    ping: ''