# db host wildcard

**URL:** <https://forum.ansible.com/t/db-host-wildcard/15253>\
**Category:** Ansible Project\
**Created:** [May 16, 2014, 10:50am UTC](https://forum.ansible.com/t/db-host-wildcard/15253 "2014-05-16T10:50:04Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wynne\_Pirini](https://avatars.discourse-cdn.com/v4/letter/w/ccd318/32.png) [@Wynne\_Pirini](https://forum.ansible.com/u/Wynne_Pirini)\
**Post date:** [May 16, 2014, 10:50am UTC](https://forum.ansible.com/t/db-host-wildcard/15253/1 "2014-05-16T10:50:04Z")

</div>

Hi there

I’m trying to set up mysql so that I can access the database from a remote client.

This is how I manually do that:

GRANT ALL PRIVILEGES ON _._ TO ‘root’@‘%’ IDENTIFIED BY ‘some pass’ WITH GRANT OPTION;

How do I achieve that with ansible?

I’m having problems getting ansible to work with the ‘%’ as a host option.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 16, 2014, 12:33pm UTC](https://forum.ansible.com/t/db-host-wildcard/15253/2 "2014-05-16T12:33:25Z")

</div>

Can you please share the command you are sending to ansible as well as the ansible version?

Thanks!

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [May 16, 2014, 1:28pm UTC](https://forum.ansible.com/t/db-host-wildcard/15253/3 "2014-05-16T13:28:28Z")

</div>

You can use the mysql\_user module for this, see the examples in [http://docs.ansible.com/mysql\_user\_module.html](http://docs.ansible.com/mysql_user_module.html)

Specifically, you’ll want something like this example:

```auto
# Creates database user 'bob' and password '12345' with all database privileges and 'WITH GRANT OPTION'
- mysql_user: name=bob password=12345 priv=*.*:ALL,GRANT state=present

```

```auto

```

---

<div class="post-metadata">

**Author:** ![Wynne\_Pirini](https://avatars.discourse-cdn.com/v4/letter/w/ccd318/32.png) [@Wynne\_Pirini](https://forum.ansible.com/u/Wynne_Pirini)\
**Post date:** [May 16, 2014, 8:21pm UTC](https://forum.ansible.com/t/db-host-wildcard/15253/4 "2014-05-16T20:21:32Z")

</div>

Hi James

I’ve poured over the docs on the ansible site and I can’t find an example with the host being set to wildcard.

Did you specify the host in your example below?

---

<div class="post-metadata">

**Author:** ![Wynne\_Pirini](https://avatars.discourse-cdn.com/v4/letter/w/ccd318/32.png) [@Wynne\_Pirini](https://forum.ansible.com/u/Wynne_Pirini)\
**Post date:** [May 16, 2014, 8:27pm UTC](https://forum.ansible.com/t/db-host-wildcard/15253/5 "2014-05-16T20:27:45Z")

</div>

Here’s the command I’m sending:

- name: Create/assign database user to db and grant permissions  
mysql\_user: name={{ item.env.db\_user }}  
password={{ item.env.db\_password }}  
priv={{ item.env.db\_name | default(item.site\_name) }}.\*:ALL,GRANT  
state=present  
login\_host={{ item.env.db\_host | default(‘localhost’) }}  
with\_items: web\_site

Where the variable web\_site.env.db\_host is the one I want to set to wildcard so I can access from remote.

With ansible version 1.6.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [May 17, 2014, 1:55am UTC](https://forum.ansible.com/t/db-host-wildcard/15253/6 "2014-05-17T01:55:38Z")

</div>

The “host” parameter for that module controls the host portion of the user login information. So you should set host=“\*” to allow connections from any remote host.

---

<div class="post-metadata">

**Author:** ![Wynne\_Pirini](https://avatars.discourse-cdn.com/v4/letter/w/ccd318/32.png) [@Wynne\_Pirini](https://forum.ansible.com/u/Wynne_Pirini)\
**Post date:** [May 17, 2014, 5:00am UTC](https://forum.ansible.com/t/db-host-wildcard/15253/7 "2014-05-17T05:00:09Z")

</div>

host=“\*” allows ansible to provision the server, but doesn’t allow me to connect via remote db client.

---

<div class="post-metadata">

**Author:** ![Wynne\_Pirini](https://avatars.discourse-cdn.com/v4/letter/w/ccd318/32.png) [@Wynne\_Pirini](https://forum.ansible.com/u/Wynne_Pirini)\
**Post date:** [May 19, 2014, 12:56am UTC](https://forum.ansible.com/t/db-host-wildcard/15253/8 "2014-05-19T00:56:17Z")

</div>

Is anyone who can successfully provision with ansible and configure the database host so that you  
can access the database from a remote location?

(I’m trying to get this working a local Vagrant setup where I use Heidi to access the guest Ubuntu machine

host=“%” is the only option that will allow me to remote access the database.

host=“\*” does not work for me.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [May 19, 2014, 8:06am UTC](https://forum.ansible.com/t/db-host-wildcard/15253/9 "2014-05-19T08:06:22Z")

</div>

That sounds about right, you want a 'sql wildcard' so % not \*.

Another gotcha - mysql treats 'localhost' specially so you might want  
a grant for that as well as %.

(I don't think this has anything to do with Ansible BTW, it's just how  
mysql works).

---

<div class="post-metadata">

**Author:** ![Ernest0x](https://avatars.discourse-cdn.com/v4/letter/e/ed655f/32.png) [@Ernest0x](https://forum.ansible.com/u/Ernest0x)\
**Post date:** [May 19, 2014, 11:56am UTC](https://forum.ansible.com/t/db-host-wildcard/15253/10 "2014-05-19T11:56:48Z")

</div>

Do you mean that host=“%” does not work for you as a parameter to mysql\_user module? This would be really strange because I have tested it with Ansible 1.6.1 and it works as expected. If you can connect from the local machine, run the following SQL “use mysql;select \* from user;” to see what has been added (or what is missing).

---

<div class="post-metadata">

**Author:** ![Wynne\_Pirini](https://avatars.discourse-cdn.com/v4/letter/w/ccd318/32.png) [@Wynne\_Pirini](https://forum.ansible.com/u/Wynne_Pirini)\
**Post date:** [May 19, 2014, 8:12pm UTC](https://forum.ansible.com/t/db-host-wildcard/15253/11 "2014-05-19T20:12:51Z")

</div>

Excellent, thanks for confirming what I had found.

---

<div class="post-metadata">

**Author:** ![Wynne\_Pirini](https://avatars.discourse-cdn.com/v4/letter/w/ccd318/32.png) [@Wynne\_Pirini](https://forum.ansible.com/u/Wynne_Pirini)\
**Post date:** [May 19, 2014, 8:14pm UTC](https://forum.ansible.com/t/db-host-wildcard/15253/12 "2014-05-19T20:14:58Z")

</div>

host=“%” works perfectly for remote access.
