我有以下 Ansible Playbook:
- hosts: vdtreportlive
vars_files:
- ./vars/postgresql.yml
- ./vars/postgresql_report.yml
roles:
- role: geerlingguy.postgresql
当我运行此命令时,出现此错误:
ERROR! couldn't resolve module/action 'postgresql_user'. This often indicates a misspelling, missing collection, or incorrect module path.
但是,如果我运行这个修改后的剧本来检查变量是否存在,我会得到预期的结果。
- hosts: vdtreportlive
vars_files:
- ./vars/postgresql.yml
- ./vars/postgresql_report.yml
tasks:
- name: Print the value of variable postgresql_user
debug:
msg: "{{ postgresql_user }} "
这会导致
ok: [vdtreportlive] => {
"msg": "postgres "
}
为什么任务可以找到变量,角色却找不到?
错误消息与 postgresql_user module 有关,而您将
postgresql_user
称为变量。
您必须确保此模块已安装,它不是 Ansible 核心的一部分。引用文档:
它不包含在 ansible-core 中。要检查是否已安装,请运行
ansible-galaxy collection list
要安装它,请使用:
ansible-galaxy collection install community.postgresql