希望这是可能的:
我正在使用Ansible清单,并试图引用另一本词典。
ansible/group_vars/myapi/user-list.yml
sysadmin_settings:
- { shell: "/bin/bash", groups: "hardworkers" }
myapi_admin_users:
- { state: "present", name: "my.user1", shell: "{{ sysadmin_settings.shell }}", groups: "{{ sysadmin_settings.groups }}" }
- { state: "present", name: "my.user2", shell: "{{ sysadmin_settings.shell }}", groups: "{{ sysadmin_settings.groups }}" }
但是我得到一个“列表对象没有属性外壳”
虽然我是我在第一个字典中要查找的内容。
理想情况下,我可以做些类似的事情:
adminapi_admin_users:
- { state: "present", name: "my.user1", type: "sysadmin" }
在我调用剧本中的项目时引用sysadmin
变量,例如,将它们与myapi_admin.groups
连接起来
谢谢
答案 0 :(得分:0)
我认为您可能正在将YAML与一些JSON(或Jinja)混在一起。通常,您想要的内容将像这样编写:
sysadmin_settings:
shell: "/bin/bash"
groups: "hardworkers"
myapi_admin_users:
- state: "present"
name: "my.user1"
shell: "{{ sysadmin_settings.shell }}"
groups: "{{ sysadmin_settings.groups }}"
- state: "present"
name: "my.user2"
shell: "{{ sysadmin_settings.shell }}"
groups: "{{ sysadmin_settings.groups }}"
这对我的系统有效。 Ansible YAML docs值得一看,并且对常见错误有有用的参考。