Re: [ansible-project] Preventing a sql script from running again?

580 views
Skip to first unread message

Lorin Hochstein

unread,
Feb 10, 2013, 6:20:29 PM2/10/13
to ansible...@googlegroups.com
Hi Simon:

Take a look at this tip: https://coderwall.com/p/7viila

Take care,

Lorin


On Sun, Feb 10, 2013 at 5:35 PM, Simon Rascovsky <sim...@gmail.com> wrote:
Hi all,

What would be a the sensible ansible way of preventing a sql script from being run if the schema is already created? Or put another way, how to make a playbook that runs a sql script idempotent?

Thanks!

Simon

--
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 ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Lorin Hochstein
Lead Architect - Cloud Services
Nimbis Services, Inc.

Romeo Theriault

unread,
Feb 10, 2013, 6:48:59 PM2/10/13
to ansible...@googlegroups.com
On Sun, Feb 10, 2013 at 12:35 PM, Simon Rascovsky <sim...@gmail.com> wrote:
Hi all,

What would be a the sensible ansible way of preventing a sql script from being run if the schema is already created? Or put another way, how to make a playbook that runs a sql script idempotent?

What Lorin pointed you at is good but if you're running the script against a remote sql server you might have to create a task ahead of the sql script task, which checks if the schema exists and store the result in a register variable. That way you can check if it's created or not. Something like this:

 tasks:

      - action: command /some/script/to/check_if_shema_exists.sql
        register: schema_exists

      - action: command /script/to/create_shema.sql
        when_string: "'${schema_exists.stdout}' == "no"


--
Romeo

Simon Rascovsky

unread,
Feb 10, 2013, 7:11:55 PM2/10/13
to ansible...@googlegroups.com
Ah..ok, that makes sense..running against a variable set by a checking script...will try it out, thanks!

Tin Tvrtković

unread,
Feb 11, 2013, 4:09:51 AM2/11/13
to ansible...@googlegroups.com
I generally drop the database before hand and recreate it (as was suggested by a few of the regulars here a few weeks ago). Sure you'll lose all your data, but it's idempotent and will apply any potential changes to the schema.


On Sunday, February 10, 2013 11:35:24 PM UTC+1, Simon Rascovsky wrote:
Hi all,

What would be a the sensible ansible way of preventing a sql script from being run if the schema is already created? Or put another way, how to make a playbook that runs a sql script idempotent?

Thanks!

Simon

Michael DeHaan

unread,
Feb 11, 2013, 8:10:54 AM2/11/13
to ansible...@googlegroups.com
That's terrible! :)
Reply all
Reply to author
Forward
0 new messages