Ansible 处理范围内的项目 [英] Ansible with items in range

查看:34
本文介绍了Ansible 处理范围内的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 ansible 实现这样的东西

I would like to achieve something like this with ansible

- debug:
    msg: "{{ item }}"
  with_items:
    - "0"
    - "1"

但是要从 range(2) 生成而不是对迭代进行硬编码.你会怎么做?

But to be generated from a range(2) instead of having hardcoded the iterations. How would yo do that?

推荐答案

- debug:
    var: item
  with_sequence: 0-1

  with_sequence: start=0 end=1

  with_sequence: start=0 count=2

注意序列是字符串值,而不是整数(你可以用item|int进行转换)

Pay attention that sequences are string values, not integers (you can cast with item|int)

参考:循环整数序列

这篇关于Ansible 处理范围内的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆