简体   繁体   English

在Ansible jinja2模板中的新行上打印输出

[英]Printing output on new lines in ansible jinja2 template

I am struggling with this script to print it's output on new lines. 我正在努力与此脚本打印在新行上的输出。 I have tried a few proposed solutions online but none seem to be working. 我已经在线尝试了一些建议的解决方案,但似乎都没有用。 Below is snippet of my playbook. 以下是我的剧本的摘要。

tasks:
 - debug: msg={% for oct in range(10,12) %}172.16.0.{{ oct }}{% endfor %}

The output i am getting is this 我得到的输出是这个

  TASK [debug] *******************************************************************
     ok: [localhost] => {
    "msg": "172.16.0.10172.16.0.11"

I need an output like this 我需要这样的输出

TASK [debug] *******************************************************************
     ok: [localhost] => {
    "msg": "172.16.0.10"
           "172.16.0.11"

I tried insert a \\n like so {% for oct in range(10,12) %}172.16.0.{{ oct }}'\\n'{% endfor %} but that only prints the \\n as a string in my output. 我试过像这样插入\\n {% for oct in range(10,12) %}172.16.0.{{ oct }}'\\n'{% endfor %}但这仅将\\n打印为字符串我的输出。

You can't achieve exactly what you want with standard output plugin. 使用标准输出插件无法完全实现所需的功能。

The closest thing is when you print ( debug ) a list – Ansible will print every item on new line: 最接近的是当您打印( debug )列表时– Ansible将在新行上打印所有项目:

---
- hosts: localhost
  connection: local
  gather_facts: no
  tasks:
    - debug: msg="{{ lookup('sequence','start=10 end=11 format=172.16.0.%d',wantlist=true) }}"

result: 结果:

ok: [localhost] => {
    "msg": [
        "172.16.0.10",
        "172.16.0.11"
    ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM