安斯布尔postgres_user成为麻烦



使用 geerlingguy.postgresql Ansible 角色,无法克服以下错误:

TASK [geerlingguy.postgresql : 确保 PostgreSQL 数据库存在。 失败: [database_host] (item=

{u'name': u'database_name'}) => {"失败": true, "item": {"name": "database_name"}, "module_stderr": "sudo: 需要密码", "module_stdout": ", "msg": "模块故障"}

任务如下所示:

- name: Ensure PostgreSQL database is initialized. 
  command: "{{ postgresql_bin_path }}/initdb -D {{ postgresql_data_dir }}" 
  when: not pgdata_dir_version.stat.exists 
  become: yes 
  become_user: "{{ postgresql_user }}" 
   # See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509 
  vars: 
    ansible_ssh_pipelining: true

postgresql_user的值是有效用户的 postgres 的操作系统默认值。 我正在连接的remote_user具有带有nopasswd的完整sudo,在此之前的所有其他任务(剧本与become: true一起运行)运行良好。 我猜这与切换到非特权用户有关,但我似乎无法弄清楚。 有什么想法吗?

/etc/sudoers中使用以下设置:

devops  ALL=(ALL) NOPASSWD: ALL

来自评论:

我正在连接的remote_user具有带有nopasswd的完整sudo。

请显示/etc/sudoers中的设置,而不是描述其假定的效果。

devops    ALL=NOPASSWD: ALL

不,它没有"完整的sudo"(无论它是什么意思)。您只允许devops用户以root身份运行命令,而不是以您在 {{ postgresql_user }} 中设置的其他用户身份运行命令。

简单 您可以在 ansible-playbook 命令中使用 --ask-sudo-pass。它将为您提供devops用户的密码提示。将条目添加到 sudoers 文件可能会导致事故。

最新更新