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

Ansible:将角色附加到postgres中的用户,ansible,ansible-2.x,Ansible,Ansible 2.x,我已经在Postgres中担任了一个角色,即readonly。它对所有数据库中的所有表具有只读访问权限 我希望将此角色附加到用户,以便他/她也可以在一个命令中获得对所有表的只读访问权限。如何使用ansible的postgresql_用户模块执行以下命令 mydb=> grant readonly to dev_username; 编辑:添加更多详细信息 这就是我尝试过的 - name: Postgres postgresql_user: login_host: xx.xx.c

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

我希望将此角色附加到用户,以便他/她也可以在一个命令中获得对所有表的只读访问权限。如何使用ansible的postgresql_用户模块执行以下命令

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}
任务执行期间发生异常。要查看完整的回溯,请使用-vvv。错误为:\ uuuu main\ uuuuu.invalidDriversError:为数据库指定的priv无效:只读
致命:[127.0.0.1]:失败!=>{“changed”:false,“module_stderr”:“Traceback(最近一次调用):\n File\”/var/folders/h1/w57gk9nx0xl8j6xb_cqv3wb0000gn/T/ansible_2ema8gl3/ansible_module_postgresql_user.py\”,第855行,在\n main()\n File\“/var/folders/h1/w57gk9nxl8j6xb_cqv3wb0000gn/T/ansible2emagl3/ansible_2eglu user.py模块中\“,第746行,在主\n privs=parse_privs(module.params[\'priv\'”,db)\n File\“/var/folders/h1/w57gk9nx0xl8j6xb_cqv3wb0000gn/T/ansible_2ema8gl3/ansible_module_postgresql_user.py\”,第686行,在parse_privs\n(type,,.join(privset.difference(有效的_privus[type]))中))\n_uuumain_uuuuu.invalidDriversError:为数据库指定的priv无效:只读\n,“模块”stdout:“消息”:“模块故障”,“rc”:1}
我也试过使用
角色属性标志:readonly
,但还是失败了。官方文档中清楚地写着
角色属性标志和
priv
中只允许一些值,我知道它不起作用,但我这么做只是为了它


ansible甚至可以做到这一点吗?

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

postgresql\u用户
ansible模块不允许您将现有角色分配给用户


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

请在评论中解释否决投票的原因谢谢,我找不到此模块,需要改进我的google foo