首页 > 解决方案 > with_items - 组合字符串属性

问题描述

我想知道是否有办法将字符串组合在一起,为 with_items 循环创建一个新的项目字符串属性。

我试过了:

with_items:
        - {first: 'one', second: '{{ item.first}}two'}

with_items:
        - {first: 'one', second: '{{ first}}two'}

  - hosts: localhost
    connection: local
    user: root
    gather_facts: no
    tasks:
    - shell: "echo {{ item.second }}"
      with_items:
        - {first: 'one', second: '{{ item.first}}-two'}

item.first = be "one"
item.second = "one-two",取 item.first 并添加到它。

标签: ansible

解决方案


递归将不起作用。测试递归是使它变得复杂的原因吗?

否则会很简单。

- shell: "echo {{ item.first }}-{{ item.second }}"
  with_items:
    - {first: 'one', second: 'two'}

推荐阅读