您好,这里有以下变量:
couchbase:
- name: incre1
ipaddress:
- 10.16.9.177
- 10.16.9.178
buckets:
- AA1
- aa1
我的plabook有以下几点:
- debug:
msg: "Running backup as {{CBBACKUPMGR}} backup -r {{ item.1 }} --cluster couchbase://{{ item.0.ipaddress }}"
register: example
with_subelements:
- "{{ couchbase }}"
- buckets
我想遍历ipaddress,然后使用bucket,所以基本上我想看看:
Running backup as /opt/ouchbase backup -r AA1 --cluster couchbase://10.16.9.177
Running backup as /opt/ouchbase backup -r aa1 --cluster couchbase://10.16.9.177
Running backup as /opt/ouchbase backup -r AA1 --cluster couchbase://10.16.9.178
Running backup as /opt/ouchbase backup -r aa1 --cluster couchbase://10.16.9.178
然而,在运行攻略时,我看到了以下内容:
Running backup as /opt/ouchbase backup -r AA1 --cluster couchbase://[u'10.16.9.177', u'10.16.9.178']
Running backup as /opt/ouchbase backup -r aa1 --cluster couchbase://[u'10.16.9.177', u'10.16.9.178']
发布于 2018-06-05 06:57:15
这不是with_subelements
所做的。如果您使用这个"debug“循环来打印{{ item }},您将看到在每次迭代中,它都会创建一个列表:
couchbase
列表中的父元素,不带该子元素的哈希,下面是输出:
TASK [debug] ********************************************************************************************************************************************************************************************************
ok: [localhost] => (item=None) => {
"msg": [
{
"ipaddress": [
"10.16.9.177",
"10.16.9.178"
],
"name": "incre1"
},
"AA1"
]
}
ok: [localhost] => (item=None) => {
"msg": [
{
"ipaddress": [
"10.16.9.177",
"10.16.9.178"
],
"name": "incre1"
},
"aa1"
]
}
PLAY RECAP
正如您所阐明的,您的意图是在ipaddress
和buckets
之间生成所有可能的组合。
要实现这一点,请尝试以下任务:
- debug:
msg: "Running backup as {{CBBACKUPMGR}} backup -r {{ item[0] }} --cluster couchbase://{{ item[1] }}"
register: example
with_items:
- "{{ lookup('nested', couchbase[0].ipaddress, couchbase[0].buckets) }}"
这里假设您的couchbase
列表变量只有一个元素,就像在您的示例中一样。
结果:
TASK [debug] ********************************************************************************************************************************************************************************************************
ok: [localhost] => (item=None) => {
"msg": "Running backup as /opt/ouchbase backup -r 10.16.9.177 --cluster couchbase://AA1"
}
ok: [localhost] => (item=None) => {
"msg": "Running backup as /opt/ouchbase backup -r 10.16.9.177 --cluster couchbase://aa1"
}
ok: [localhost] => (item=None) => {
"msg": "Running backup as /opt/ouchbase backup -r 10.16.9.178 --cluster couchbase://AA1"
}
ok: [localhost] => (item=None) => {
"msg": "Running backup as /opt/ouchbase backup -r 10.16.9.178 --cluster couchbase://aa1"
}
PLAY RECAP
希望能有所帮助。
https://stackoverflow.com/questions/50689572
复制相似问题