Coming into this discussion a little late, but here's an example to 
illustrate what's being suggested:

Play:

- name: Ensure example database exists.
  mysql_db: name=exampledb state=present
  notify: import example database

Handler:

- name: import example database
  mysql_db: name=example state=import target=/path/to/example_schema.sql

This works great, and avoids errors I was getting when I tried doing the 
import straightaway; the import only seems to work if the database already 
exists.

On Tuesday, November 26, 2013 3:12:25 PM UTC-6, Fred Badel wrote:
>
> I don’t know why, but in my mind, notifying handlers was only to restart a 
> service … now I can see the light!! :)
>
> Although, this would not help if the db exists but is empty, you just help 
> me understand how I can use and how useful “notify” can be !  
>
> Thank you.
>
> fred
>
> On Nov 26, 2013, at 19:18 , David Karban <[email protected] <javascript:>> 
> wrote:
>
> Hi, 
>
> you can use notify in create DB to create schema. That way, it will be 
> called only on db creation.
>
> David
>  Dne 26.11.2013 17:42 "Fred Badel" <[email protected] <javascript:>> 
> napsal(a):
>
>> Hello,
>>
>> I have a playbook that create a mysql DB and import an empty schema:
>>
>> - name: create DB
>>   mysql_db: name={{ db_name }} state=present login_host=127.0.0.1 
>>
>> - name: create schema
>>   mysql_db: name={{ db_name }} state=import login_host=127.0.0.1 
>> target=/create_tables.sql 
>>
>> From what i could notice, the sql file is imported each time the playbook 
>> is run ... (aka, the task is marked as changed each time I run the playbook)
>> is this an expected behavior?
>> does someone have a recommended way of using the import feature and run 
>> it only once?
>>
>> Thanks.
>>
>> Fred
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to