Dictionary Ansible如何创建字典键列表

Dictionary Ansible如何创建字典键列表,dictionary,variables,ansible,nested-lists,Dictionary,Variables,Ansible,Nested Lists,我可能错过了一些简单的东西。我有这本字典 deploy_env: dev: schemas: year1: - main - custom year2: - main - custom - security year3: - main - custom 然后在我的剧本里,我有 - set_fact: years: "{{ dep

我可能错过了一些简单的东西。我有这本字典

deploy_env:
  dev:
    schemas:
      year1:
        - main
        - custom
      year2:
        - main
        - custom
        - security
      year3:
        - main
        - custom
然后在我的剧本里,我有

- set_fact:
    years: "{{ deploy_env.dev.schemas }}"

- name: Create schemas
  shell: "mysql ....params go here... {{ item }}"
  with_nested:
    - "{{ years }}"
如果vars.yml中的模式是一个简单的列表,即:

...schemas:
     - year1
     - year2
     - year3
但是,一旦我在每年增加额外的项目(使之成为一本词典(?),我就开始在这行上出现错误:-“{years}”

我基本上想为这个任务用year1、year2、year3值填充{{years}}

我看过很多例子,但我所看到的一切都非常复杂,都是关于如何创建字典的,这是没有帮助的


谢谢!

可以创建字典键列表。例如

-设置事实:
年份:“{deploy_env.dev.schemas.keys()| list}”
-调试:
变量:项目
循环:“{years}}”
给予

“项目”:“第1年”
“项目”:“第2年”
“项目”:“第3年”

**列表与字典** 引述:

“在每年下添加其他项目(使其成为词典(?)

添加项目不会将列表更改为字典。列表中的项目在中以破折号“-”引入。在列表的每个项目下添加其他项目将使其成为列表列表

列表示例:

模式:
-第一年
-第二年
-第三年
列表列表的示例

模式:
-第一年:
-主要
-习俗
-第2年:
-主要
-习俗
-保安
-第3年:
-主要
-习俗
词典示例:

模式:
第一年:
-主要
-习俗
第2年:
-主要
-习俗
-保安
第3年:
-主要
-习俗