gpt4 book ai didi

postgresql - 如何将 postgres 连接到 ansible?

转载 作者:行者123 更新时间:2023-11-29 13:39:28 26 4
gpt4 key购买 nike

目标:

我的目标是使用 Ansible 2.8.3 连接 postgres 9.3,并使用 ansible 执行 postgres 操作。

我创建了一个 yaml 文件来安装 postgres,这个文件还使用 yaml 脚本创建了一个数据库。

我尝试通过更改 sudoer 文件的内容来解决此错误,但它损坏了文件,迫使我重新安装 ubuntu 和 ansible。

Ansible 代码:


- hosts: localhost
become: yes
gather_facts: no

tasks:
- name: ensure apt cache is up to date
apt: update_cache=yes
- name: ensure packages are installed
apt: name={{item}}
with_items:
- postgresql
- libpq-dev
- python-psycopg2

- hosts: localhost
become: yes
become_user: emgda
gather_facts: no

vars:
dbname: myapp
dbuser: emgda
dbpassword: Entrib!23

tasks:
- name: ensure database is created
postgresql_db: name={{dbname}}

- name: ensure user has access to database
postgresql_user: db={{dbname}} name={{dbuser}} password={{dbpassword}} priv=ALL

- name: ensure user does not have unnecessary privilege
postgresql_user: name={{dbuser}} role_attr_flags=NOSUPERUSER,NOCREATEDB

- name: ensure no other user can access the database
postgresql_privs: db={{dbname}} role=PUBLIC type=database priv=ALL state=absent

...

运行此文件后,我遇到了以下错误:

致命:[本地主机]:失败! => {"changed": false, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

NOTE: Can anyone kindly help me resolve this issue. I am new to Ansible. I am following this link to practice already running Ansible script.

最佳答案

你已经在你的 playbook 中设置了 become: yes ,所以很容易尝试切换到 root 用户。根据错误信息-sudo: a password is required,你在playbook运行时没有设置--ask-become-pass选项,也没有设置您的 ansible 用户的无密码 sudo。

因此,您需要使用 --ask-become-pass 选项运行您的 playbook,或者为您使用 Ansible 的用户设置使用无密码 sudo 的能力。

关于postgresql - 如何将 postgres 连接到 ansible?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57476437/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com