2016-10-27 19 views
6

Điều này sẽ rất đơn giản. Tôi muốn tạo một câu lệnh Ansible để tạo một người dùng Postgres có các đặc quyền kết nối tới một cơ sở dữ liệu cụ thể và chọn/insert/update/delete các đặc quyền cho tất cả các bảng trong cơ sở dữ liệu cụ thể đó. Tôi thử như sau:Ansible tạo người dùng postgresql có quyền truy cập vào tất cả các bảng?

- name: Create postgres user for my app 
    become: yes 
    become_user: postgres 
    postgresql_user: 
     db: "mydatabase" 
     name: "myappuser" 
     password: "supersecretpassword" 
     priv: CONNECT/ALL:SELECT,INSERT,UPDATE,DELETE 

tôi nhận được relation \"ALL\" does not exist

Nếu tôi loại bỏ ALL:, tôi nhận được Invalid privs specified for database: INSERT UPDATE SELECT DELETE

Trả lời

2

Những gì tôi phải làm trước tiên là tạo người dùng và sau đó cấp các đặc quyền riêng biệt. Nó hoạt động như một sự quyến rũ.

- name: Create postgres user for my app 
    become: yes 
    become_user: postgres 
    postgresql_user: 
     name: "myappuser" 
     password: "supersecretpassword" 

    - name: Ensure we have access from the new user 
    become: yes 
    become_user: postgres 
    postgresql_privs: 
     db: mydatabase 
     role: myappuser 
     objs: ALL_IN_SCHEMA 
     privs: SELECT,INSERT,UPDATE,DELETE 
0

Từ tài liệu ansible postgressql module, priv nên được "đặc quyền PostgreSQL chuỗi trong các định dạng: bảng: priv1 , priv2 " Vì vậy, nhiệm vụ của bạn phải là

- name: Create postgres user for my app 
    become: yes 
    become_user: postgres 
    postgresql_user: 
     db: "mydatabase" 
     name: "myappuser" 
     password: "supersecretpassword" 
     priv: ALL:SELECT,INSERT,UPDATE,DELETE,CONNECT 
+0

Điều này không hiệu quả đối với tôi. Tôi gặp lỗi 'psycopg2.ProgrammingError: quan hệ \" ALL \ "không tồn tại' – Inti

Các vấn đề liên quan