Ansible - passing JSON string in environment to shell module

后端 未结 2 2057
谎友^
谎友^ 2020-12-10 19:20

I am trying to pass JSON string in environment.

- name: Start {{service_name}}
  shell: \"<> --server.port={{service_por         


        
2条回答
  •  情歌与酒
    2020-12-10 20:14

    There is a thing about Ansible template engine.
    If a string seems like an object (starts with { or [) Ansible converts it into object. See code.

    To prevent this, you may use one of STRING_TYPE_FILTERS:

    - SPRING_APPLICATION_JSON: "{{ {'test-host.1':test_host_1,'test-host.2':test_host_2} | to_json }}"
    

    P.S. this is why hack with space character from @techraf's answer works: Ansible misses startswith("{") comparison and don't convert string to object.

提交回复
热议问题