Ansible:将角色附加到postgres中的用户
Ansible: Attach role to user in postgres
我已经在 Postgres 中扮演了一个角色,即 readonly
。它对所有数据库中的所有表具有只读访问权限。
我想将此角色附加到用户,这样 he/she 也可以通过一个命令获得对所有表的只读访问权限。如何使用 ansible 的 postgresql_user 模块执行以下命令?
mydb=> grant readonly to dev_username;
编辑:添加更多详细信息
这是我试过的,
- 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
它给我这个错误,
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}
我也试过 role_attr_flags: readonly
,但还是失败了。官方文档里写得很清楚,role_attr_flags
和 priv
中只允许有一些值,我知道这行不通,但我只是为了它才这样做。
这甚至可以用 ansible 实现吗?
postgresql 术语回顾:一个用户就是一个角色,一个组就是一个角色。第一个有登录权限,第二个通常没有。
postgresql_user
ansible 模块不允许您将现有角色分配给用户。
您需要先创建用户,然后使用 postgresql_membership
附加其他角色
我已经在 Postgres 中扮演了一个角色,即 readonly
。它对所有数据库中的所有表具有只读访问权限。
我想将此角色附加到用户,这样 he/she 也可以通过一个命令获得对所有表的只读访问权限。如何使用 ansible 的 postgresql_user 模块执行以下命令?
mydb=> grant readonly to dev_username;
编辑:添加更多详细信息
这是我试过的,
- 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
它给我这个错误,
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}
我也试过 role_attr_flags: readonly
,但还是失败了。官方文档里写得很清楚,role_attr_flags
和 priv
中只允许有一些值,我知道这行不通,但我只是为了它才这样做。
这甚至可以用 ansible 实现吗?
postgresql 术语回顾:一个用户就是一个角色,一个组就是一个角色。第一个有登录权限,第二个通常没有。
postgresql_user
ansible 模块不允许您将现有角色分配给用户。
您需要先创建用户,然后使用 postgresql_membership