我有这个yaml结构
myProgram:
- year: year
exepath: My:FilePath.exe
product_id: '{My-Product-ID}'
product_key: 'My-Product-Key'
version: version
args: '/passive /norestart /full /p ProductKey= "{{ _________ }}"' # Call product_key in the blank
我最初将myProgram[0].product_key
留空,但这返回了一个递归错误。我该在空白处写些什么,还是这不可能?
我认为您所要求的是不可能的,但是可以使用yaml alias
:完成一些接近的操作
---
- name: Sample playbook
connection: local
gather_facts: false
hosts: localhost
tasks:
- set_fact:
myProgram:
- year: year
exepath: My:FilePath.exe
product_id: &anchor '{My-Product-ID}'
product_key: 'My-Product-Key'
version: version
#args: '/passive /norestart /full /p ProductKey= "{{ *anchor }}"' #This does not work
args: *anchor #This works
- debug: var=myProgram
这个程序的输出是,请注意,我们没有将args
设置为等于product_id
,而是使用alias
来替换args节点。据我所知,我们不能使用alias
连接字符串,只能替换整个节点。
PLAY [Sample playbook] **********************************************************************************************************************************************
TASK [set_fact] *****************************************************************************************************************************************************
ok: [localhost]
TASK [debug] ********************************************************************************************************************************************************
ok: [localhost] => {
"myProgram": [
{
"args": "{My-Product-ID}", <--------THIS is alias to product_id
"exepath": "My:\File\Path.exe",
"product_id": "{My-Product-ID}", <--------THIS
"product_key": "My-Product-Key",
"version": "version",
"year": "year"
}
]
}
PLAY RECAP **********************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0