Ansible:在 postgres 中将角色附加到用户

Luv*_*eet 2 ansible ansible-2.x

我已经在 Postgres 中扮演了一个角色readonly。它对所有数据库中的所有表具有只读访问权限。

我想将此角色附加给用户,以便他/她也可以通过一个命令获得对所有表的只读访问权限。如何使用 ansible 的 postgresql_user 模块执行以下命令?

mydb=> grant readonly to dev_username;
Run Code Online (Sandbox Code Playgroud)

编辑:添加更多细节

这是我尝试过的,

- name: Postgres
  postgresql_user:
    login_host: xx.xx.com
    login_password: mypassword
    login_user: myuser
    db: mydb
    name: dev_username
    password: mypassword
    priv: "readonly"
    expires: infinity
    state: present
Run Code Online (Sandbox Code Playgroud)

它给了我这个错误,

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: __main__.InvalidPrivsError: Invalid privs specified for database: READONLY
fatal: [127.0.0.1]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/h1/w57gk9nx0xl8j6xb_cqv3wb00000gn/T/ansible_2ema8gl3/ansible_module_postgresql_user.py\", line 855, in <module>\n    main()\n  File \"/var/folders/h1/w57gk9nx0xl8j6xb_cqv3wb00000gn/T/ansible_2ema8gl3/ansible_module_postgresql_user.py\", line 746, in main\n    privs = parse_privs(module.params[\"priv\"], db)\n  File \"/var/folders/h1/w57gk9nx0xl8j6xb_cqv3wb00000gn/T/ansible_2ema8gl3/ansible_module_postgresql_user.py\", line 686, in parse_privs\n    (type_, ' '.join(priv_set.difference(VALID_PRIVS[type_]))))\n__main__.InvalidPrivsError: Invalid privs specified for database: READONLY\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}
Run Code Online (Sandbox Code Playgroud)

我也尝试过role_attr_flags: readonly,但再次失败。官方文档中明确写着role_attr_flags和中只允许使用一些值priv,我知道它行不通,但我只是为了它而这样做。

这对于 ansible 来说是可能的吗?

Zei*_*tor 6

postgresql 术语回顾:用户是一个角色,一个组是一个角色。第一个具有登录权限,第二个通常没有。

postgresql_useransible 模块不允许您将现有角色分配给用户。

您需要首先创建用户,然后附加其他角色postgresql_membership