[英]How to reference variable value in index
當我對值進行硬編碼時,它可以正常工作。例如-
- name: display number
debug:
msg: "{{ ansible_facts.partition[2] }}"
輸出
ok: [host] => {
"msg": "786"
}
但是當我動態找到變量的值並引用該值時,它不起作用。
- name: display number
debug:
msg: "{{ ansible_facts.partition[number] }}"
## Where: number = 2, finding this value dynamically and setting as fact
輸出
The error was: 'list object' has no attribute u'2'
我也嘗試使用將數字變量轉換為整數
set_fact:
number: "{{ number | int }}"
但是沒有運氣。 任何人都可以提供幫助,我們將不勝感激。
嘗試如下:
- name: display number
debug:
msg: "{{ ansible_facts.partition[number|int] }}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.