It looks like the mysql_db module will blindly run mysqldump wiht the
specified target file if it's specified, so yes it's currently expected
behavior.
What you would probably need to do is run an action before you call
mysql_db that checks to see if the database already exists and register a
variable so that you can call create DB only if you need to. This could be
something along the lines of:
-name: check if DB exists
shell: mysql -u <user> -p <password> -h <host> 'show databases;' | grep {{
db_name }}
register: dbstatus
If you run that with -vvv you'll see all the facts available in the
dbstatus variable, and one of them can be used in a 'when' clause for your
mysql_DB call.
-Bruce
On Tuesday, November 26, 2013 11:42:42 AM UTC-5, Fred Badel wrote:
>
> 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].
For more options, visit https://groups.google.com/groups/opt_out.