如何将字典变量传递给 Ansible Role?
How to pass variable that's a dictionary into Ansible Role?
我想将一些值传递给 Ansible 角色,但我在文档中找不到任何示例来说明如何传递字典变量。
这是我想传递的内容,但我的 YAML 语法已关闭:
roles:
- { role: postgresql,
postgresql_users:
- name: dev_user
pass: dev_pass
encrypted: no,
- name: test_user
pass: test_pass
encrypted: no
postgresql_databases: ['dev', 'test'],
postgresql_user_privileges:
- name: dev_user
db: dev
priv: "ALL"
- name: test_user
db: test
priv: "ALL"
tags: ['postgres']
}
传递这些具有字典值的变量的正确 YAML 语法是什么?
我觉得应该更接近于这个:
roles:
- { role: postgresql,
postgresql_users: [
{ name: "dev_user",
pass: "dev_pass",
encrypted: "no" },
{ name: "test_user",
pass: "test_pass",
encrypted: "no" }
],
postgresql_databases: ['dev', 'test'],
postgresql_user_privileges:[
{ name: "dev_user",
db: "dev",
priv: "ALL" },
{ name: "test_user",
db: "test",
priv: "ALL"}
],
tags: ['postgres']
}
请注意,我假设 "dev_user" 等人。是字符串。如果你想要变量,你需要name: "{{ dev_user }}"
我想将一些值传递给 Ansible 角色,但我在文档中找不到任何示例来说明如何传递字典变量。
这是我想传递的内容,但我的 YAML 语法已关闭:
roles:
- { role: postgresql,
postgresql_users:
- name: dev_user
pass: dev_pass
encrypted: no,
- name: test_user
pass: test_pass
encrypted: no
postgresql_databases: ['dev', 'test'],
postgresql_user_privileges:
- name: dev_user
db: dev
priv: "ALL"
- name: test_user
db: test
priv: "ALL"
tags: ['postgres']
}
传递这些具有字典值的变量的正确 YAML 语法是什么?
我觉得应该更接近于这个:
roles:
- { role: postgresql,
postgresql_users: [
{ name: "dev_user",
pass: "dev_pass",
encrypted: "no" },
{ name: "test_user",
pass: "test_pass",
encrypted: "no" }
],
postgresql_databases: ['dev', 'test'],
postgresql_user_privileges:[
{ name: "dev_user",
db: "dev",
priv: "ALL" },
{ name: "test_user",
db: "test",
priv: "ALL"}
],
tags: ['postgres']
}
请注意,我假设 "dev_user" 等人。是字符串。如果你想要变量,你需要name: "{{ dev_user }}"