Ansible: Using node anchors and merge keys split over different yaml files

前端 未结 2 789
眼角桃花
眼角桃花 2020-12-22 07:30

I\'m having difficulty getting Ansible to work with YAML merge keys and node anchors and wondering whether these can work when they are in different files and what might be

相关标签:
2条回答
  • 2020-12-22 08:29

    I'm having difficulty getting Ansible to work with YAML merge keys and node anchors and wondering whether these can work when they are in different files and what might be an alternative approach.

    Merge keys and node anchors cannot be used across files. They are only useful within a single YAML document.

    I get the following cryptic error:

    "exception: found undefined alias" seems to accurately describe the problem.

    Can anyone suggest whether/how this can work or whether there's another approach that can achieve this aim?

    You can use the combine filter:

    process_settings: "{{ default_process_settings|combine({'heartbeat_rate':    '5'}) }}"
    

    The same, but perhaps easier to read (and easier to write, especially if you've got more than a single key):

    override_process_settings:
        heartbeat_rate:    "5"
    
    process_settings: "{{ default_process_settings|combine(override_process_settings) }}"
    
    
    
    0 讨论(0)
  • 2020-12-22 08:30

    Although the merge key document doesn't say anything about multiple documents

    But the YAML specification is very explicit about the use of aliases:

    It is an error for an alias node to use an anchor that does not previously occur in the document

    So an alias is invalid if it is in the same file, but referencing a different document, and you try to reference an anchor in a document in a different file, so that is not valid either.

    0 讨论(0)
提交回复
热议问题