使用Ansible jinja过滤器生成多行YAML

2024-10-01 11:26:01 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Ansible,to_yamljinja过滤器,我想生成以下YAML编码的字符串:

data: |
   hello: world
   bonjour: monde

例如:

      - set_fact:
          my_data:
            data: |
              hello: world
              bonjour: monde
      - debug:
          msg: "{{ my_data | to_nice_yaml }}" 

给予

{
  - msg: data: 'hello: world

             bonjour: monde

             '
}

Tags: to字符串过滤器yamlhello编码worlddata