Creation of several users with access to a personal database

43 Views Asked by At

Needed to create seven databases, for each database you need one user with the same name as the database.

db_names:
   - keystone
   - neutron
   - glance
   - placement
   - nova
   - nova_api
   - nova_cell0
- name: Create user with password
  mysql_user:
    login_unix_socket: "{{ mariadb_login_unix_socket }}"
    login_user: root
    login_password: "{{ mysql_root_pass }}"
    state: present
    name: "{{ db_names }}"
    password: "{{ mysql_root_pass }}"
    update_password: always
    priv:
      "{{ db_names }}.*:ALL,GRANT"

At the moment, a row is being created in the database with all the names in one row.

1

There are 1 best solutions below

0
On

You could use loop like this:

tasks:
  - name: Create user with password
    mysql_user:
      login_unix_socket: "{{ mariadb_login_unix_socket }}"
      login_user: root
      login_password: "{{ mysql_root_pass }}"
      state: present
      name: "{{ item }}"
      password: "{{ mysql_root_pass }}"
      update_password: always
      priv:
        "{{ item }}.*:ALL,GRANT"
      with_items: ["dbname1", "dbname2", "dbname3"]