小编Cod*_*irl的帖子

ansible 循环中的 Jinja 模板

我需要根据 CSV 文件的输入运行 ansible 循环。我正在使用以下问题/答案作为参考。但是,我似乎无法弄清楚在哪里实际包含循环的 jinja 部分。

到目前为止,这就是我所拥有的,但它会引发错误:

---
- hosts: localhost
  connection: local
  gather_facts: no

  vars:
    csv_var: "{{ lookup ('file', 'file.csv') }}"

  tasks:
  - debug:
      msg: "{{ item }}"
    with_items:
      - {% set list = csv_var.split(",") %}
Run Code Online (Sandbox Code Playgroud)

file.csv有以下内容:345,1234,1234

理想情况下,该消息应打印出上面的数字。

我得到的语法错误是:

The offending line appears to be:

    with_items:
      - {% set list = csv_var.split(",") %}
         ^ here

exception type: <class 'yaml.scanner.ScannerError'>
exception: while scanning for the next token
found character that cannot start any token
  in …
Run Code Online (Sandbox Code Playgroud)

jinja2 ansible

1
推荐指数
1
解决办法
505
查看次数

标签 统计

ansible ×1

jinja2 ×1