从ansible中的with_序列检索索引值
如何检索ansible中with_序列循环中使用的索引“{item}}”值? 我使用以下代码:从ansible中的with_序列检索索引值,ansible,Ansible,如何检索ansible中with_序列循环中使用的索引“{item}}”值? 我使用以下代码: - name: Check if Route 53 DNS record exists route53: state: get zone: zone_id private_zone: true record: testrecord{{ item }}.foo.com type: A register: dns_record when: (dns_re
- name: Check if Route 53 DNS record exists
route53:
state: get
zone: zone_id
private_zone: true
record: testrecord{{ item }}.foo.com
type: A
register: dns_record
when: (dns_record is not defined) or (dns_record.set | length > 0)
with_sequence: start=0 end=9
当这个代码块退出时,我无法检索{{item}}值。以后我如何仍然使用这个值
当这个代码块退出时,我无法检索{{item}}值。以后我如何仍然使用这个值
事实并非如此;如果您检查了寄存器中的变量:
(使用类似于-debug:var=dns\u record
)您会发现有一个结果
列表,它是一个列表[dict]
,顶级键为项
,显示每个迭代中项
的值
任务:
-调试:
msg:item是{{item}
按顺序:开始=0结束=5
注册:注册项目
-debug:var=_项
产生
TASK [debug] ********************************************************************************************************************
ok: [localhost] => {
"the_items": {
"changed": false,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"item": "0",
"msg": "item is 0"
},
我想我很愚蠢,因为我没有看到这个。。。我会看一看。。。这是使用循环时返回循环索引的正常方式吗?你是对的,它有我所需要的一切,我没有正确地查看它,谢谢