PostgreSQL INSERT

42 views
Skip to first unread message

zerozer...@gmail.com

unread,
May 27, 2014, 7:42:00 AM5/27/14
to puppet...@googlegroups.com
Hi,
how can I use Puppet to insert a row in a table inside a PostgreSQL database?

Of course I could manage it through an Exec resource, but isn't there a more "elegant" solution?
I would also need to be sure the line isn't already there, before inserting it...

I'm looking at the supported module https://forge.puppetlabs.com/puppetlabs/postgresql, but to be sincere I'm still not sure how it works and if it really fits my need.

Thank you.
Marco

Dirk Heinrichs

unread,
May 27, 2014, 7:54:18 AM5/27/14
to puppet...@googlegroups.com
Am 27.05.2014 13:42, schrieb zerozer...@gmail.com:

Of course I could manage it through an Exec resource, but isn't there a more "elegant" solution?
I would also need to be sure the line isn't already there, before inserting it...

I wonder what's wrong with exec? I use for example:

  exec { 'create_app_schema':
    command     => 'psql -t -A -q -c "create schema app authorization someuser" somedb pg_admin',
    path        => ["${installdir}/bin", $::path],
    unless      => 'cmd /C psql -t -A -q -c "select nspname from pg_catalog.pg_namespace where nspname = \'app\';" somedb pg_admin | find "app"',
    require     => [Windows_env['PGPASSWORD'], Service['postgres'], Exec['create_db']],
    environment => ["PGPASSWORD=${password}"],
  }

This executes the command for creating a schema, if it doesn't exist already.

Of course, you could try to write your own resource type and provider for db queries, but I doubt it won't buy you anything except for a cleaner syntax and maybe platform independence.

HTH...

    Dirk
--

Dirk Heinrichs, Senior Systems Engineer, Engineering Solutions
Recommind GmbH, Von-Liebig-Straße 1, 53359 Rheinbach
Tel: +49 2226 1596666 (Ansage) 1149
Email: d...@recommind.com
Skype: dirk.heinrichs.recommind
www.recommind.com

Felix Frank

unread,
May 27, 2014, 8:01:48 AM5/27/14
to puppet...@googlegroups.com
On 05/27/2014 01:54 PM, Dirk Heinrichs wrote:
> I wonder what's wrong with exec?

The general module design goal is to implement types/providers for most
tasks, which has some benefits:

- bulk prefetching (of table data in this case) may be an option
- single properties of system entities can be modeled separately
- the agent will make more succinct and useful reports
- it's therefor easier *and* more performant to implement fine grained
management

...there may be more.

Exec is mainly a crutch for places in which no provider is yet
available. It can be worthwile in some instances, of course, but in the
majority of applications, there is a strong case for type support.

Regards,
Felix

zerozer...@gmail.com

unread,
May 28, 2014, 8:03:49 AM5/28/14
to puppet...@googlegroups.com
Il giorno martedì 27 maggio 2014 13:54:18 UTC+2, Dirk Heinrichs ha scritto:
 
I wonder what's wrong with exec? I use for example:

Thank you, I'll try to adapt your example to my needs (I'm on Linux so some of your parameters won't fit), although I have the same feeling Felix expressed.
But if no module exists for doing what I need, exec will do ;).

Marco.

Dirk Heinrichs

unread,
May 28, 2014, 8:06:55 AM5/28/14
to puppet...@googlegroups.com
Am 27.05.2014 14:01, schrieb Felix Frank:

Exec is mainly a crutch for places in which no provider is yet
available. It can be worthwile in some instances, of course, but in the
majority of applications, there is a strong case for type support.

While I surely agree with you here, the problem from my PoV is that such a type provider would be pretty complex.

Bye...
Reply all
Reply to author
Forward
0 new messages