Usage of aws module from resource abstraction layer

50 views
Skip to first unread message

Sergey Zemlyanoy

unread,
Mar 3, 2016, 3:12:16 PM3/3/16
to Puppet Users

Hey folks,

How you guys maintain your ec2 instances using aws module from command line? I intend to rely on RAL or mco to be able to provision instances on demand, without declaring them in puppet/hiera, but just take defaults from there. I want to let my build server to execute command like:

puppet resource ec2_instance <hostname> ensure=present =<value>

so it could take defaults(ami, region etc) from hiera and kick few build instances with unique hostnames.

I faced with some issues here: not all params can be passed to RAL, namely user_data, blockdevices


puppet resource ec2instance someinstance ensure=present region=eu-central-1 imageid=xxxxx securitygroups='xxxxx' subnet=xxxxx instancetype=m3.medium blockdevices=[{'deleteontermination':'true', 'volumesize':10, 'devicename':'/dev/sda'}] Error: Could not run: Invalid parameter setting volumesize:10,


seems its not possible to pass hash to 'puppet resource' either.

Any thoughts on how can I pass these attributes or how to force usage of defaults from hiera?

Much appreciated, Sergey

Gareth Rushgrove

unread,
Mar 4, 2016, 3:57:14 AM3/4/16
to puppet...@googlegroups.com
On 3 March 2016 at 20:12, Sergey Zemlyanoy <s.zem...@gmail.com> wrote:
> Hey folks,
>
> How you guys maintain your ec2 instances using aws module from command line?
> I intend to rely on RAL or mco to be able to provision instances on demand,
> without declaring them in puppet/hiera, but just take defaults from there. I
> want to let my build server to execute command like:
>
> puppet resource ec2_instance <hostname> ensure=present =<value>
>
> so it could take defaults(ami, region etc) from hiera and kick few build
> instances with unique hostnames.
>
> I faced with some issues here: not all params can be passed to RAL, namely
> user_data, blockdevices
>
>
> puppet resource ec2instance someinstance ensure=present region=eu-central-1
> imageid=xxxxx securitygroups='xxxxx' subnet=xxxxx instancetype=m3.medium
> blockdevices=[{'deleteontermination':'true', 'volumesize':10,
> 'devicename':'/dev/sda'}] Error: Could not run: Invalid parameter setting
> volumesize:10,
>
>
> seems its not possible to pass hash to 'puppet resource' either.
>

Yup, that's the current issue with that you propose via puppet resource.

The other approach is to use the -e (execute) flag on puppet apply like so:

http://www.puppetcookbook.com/posts/simple-adhoc-execution-with-apply-execute.html

As it sounds like you're automating this anyway that should just be a
matter of syntax, rather than the simple key=value pairs that resource
uses you can use the full Puppet language. Which also means you could
create some basic defined types which provide the defaults and only
pass in the variables that change.

Gareth

> Any thoughts on how can I pass these attributes or how to force usage of
> defaults from hiera?
>
> Much appreciated, Sergey
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/5e530737-2231-489c-b5e1-1f8f480ff772%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Gareth Rushgrove
@garethr

devopsweekly.com
morethanseven.net
garethrushgrove.com

Sergey Zemlyanoy

unread,
Mar 4, 2016, 5:55:15 AM3/4/16
to Puppet Users
Thanks for reply,

Will check that link.
Re defined type this is what I already was thinking about but I literally can't call my new type from RAL command while it works perfectly for generic puppet applies. From what I know only ruby types can be passed to 'puppet resource', am I right?

Thnaks

Gareth Rushgrove

unread,
Mar 4, 2016, 8:02:48 AM3/4/16
to puppet...@googlegroups.com
This is unfortunately true at present. However if you use the puppet
apply -e trick you can use defined types.

> Thnaks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/e60aae5a-61bf-4238-99c2-6bdcf3feed0f%40googlegroups.com.

Sergey Zemlyanoy

unread,
Mar 4, 2016, 8:05:59 AM3/4/16
to Puppet Users
Regarding advise to use 'puppet apply -e'

Some odd issue with processing resource $title by erb template

I call

puppet apply -e "ec2_instance {"szemlyanoy-test-5": ensure => present, region => eu-west-1, image_id => ami-12249661, instance_type => 'm3.medium', key_name => 'CLI_Deploy', security_groups => ['Allow all'], subnet =>  'ec2_generic', user_data => template('files/aws_ec2_init.sh.erb'), block_devices => [{'device_name' => '/dev/sda1', 'delete_on_termination' => 'true', volume_size => 15}]}"

where in template('files/aws_ec2_init.sh.erb')  I use few commands like

#!/bin/bash
hostnamectl set-hostname <%= @title %>.somedomain

and it applies hostname 'main.somedomain'

So cannot get from where this $title evaluates to 'main' ?


Thanks in advance

Sergey Zemlyanoy

unread,
Mar 4, 2016, 11:44:41 AM3/4/16
to Puppet Users
ignore it

Fixed by invoking command with defined type which pass params into ec2_instance type.

The last thing bothers me - I cannot make 'puppet apply -e'  to lookup for params from hiera or even puppet classes, so need to pass all keys from cli which is inconvenient
Reply all
Reply to author
Forward
0 new messages