running a mysql command via ansible to create a user in a mysql docker container

Hi all

Run into a bit of a problem when trying to run this command inside a docker container:

CREATE USER ‘{{ item.user }}’@‘%’ IDENTIFIED BY ‘{{ item.password }}’;

this is what I’ve done but it’s not working. Does anybody see where I’m going wrong? (where mysql in the example command-line is the container name)

- name: Build the environment

hosts: server1

tasks

- name: create db users via command line

shell: "docker exec -i mysql sh -c ‘mysql -u root -e "CREATE USER ‘{{ item.user }}’@’%’ IDENTIFIED BY ‘{{ item.password }}’;" ’ "

with_items:

- { user: “user1”, password: “aaaaaaaaa”, db: “db1” }

- { user: “user2”, password: “bbbbbbbbb”, db: “db2” }

- { user: “user3”, password: “cccccccccc”, db: “db3” }

Hope you can point me in the right direction

Regards

John

Hi all

Run into a bit of a problem when trying to run this command inside a docker container:

        *CREATE USER '{{ item.user }}'@'%' IDENTIFIED BY '{{ item.password }}';*

this is what I've done but it's not working. Does anybody see where I'm going wrong? (where mysql in the example
command-line is the container name)

        *- name: Build the environment*

        * hosts: server1*

        * tasks*

        * - name: create db users via command line*

        * shell: "docker exec -i mysql sh -c 'mysql -u root -e \"CREATE USER '{{ item.user }}'@'%' IDENTIFIED BY
        '{{ item.password }}';\" ' "*

        * with_items:*

        * - { user: "user1", password: "aaaaaaaaa", db: "db1" }*

        * - { user: "user2", password: "bbbbbbbbb", db: "db2" }*

        * - { user: "user3", password: "cccccccccc", db: "db3" }*

Hope you can point me in the right direction

Hello John,

I don't see the point why you want to do this from inside the container. You should be able to use "mysql_user" module
with the MySQL port exposed by the docker container.

Regards
         Racke