>>
>>
>>>> I have a number of 'defines' and not actual classes.
>>>
>>> Based on the usage below they should be defines and not classes. If
>>> your issue is defines are resources and you have no ability to create
>>> resources via the ENC, look at create_resource function (in 2.7 and
>>> backported as a module for 2.6), essentially you will write a wrapper
>>> class that accepts a list of attributes and then create the
>>> appropriate resources.
>>>
>>>> I switched one of them over to a parameterized class and I was able to use parameters to pass in the needed values so I know I can make it work but I can sense that I will have to do a little refactoring because I can't have identically named parameters (untested but I am sure this will be a headache).
>>>>
>>>> But one of the things I really want to do is to be able to have multiple apache/nginx vhosts which in the 'define' world, allowed me to separately define each vhost and I can't think of a way I can get that done using the parameters as I understand them.
>>>>
>>>> for example, in one of my test nodes, I have…
>>>>
>>>> apache::vhost { "test.ttinet":
>>>> port => 8080,
>>>> docroot => "/var/www/test.ttinet",
>>>> ssl => false,
>>>> priority => 10,
>>>> rails_env => 'development',
>>>> passenger_enable => 'no',
>>>> serveraliases => ['test', 'test2'],
>>>> }
>>>> apache::vhost { "test2.ttinet":
>>>> port => 8080,
>>>> docroot => "/var/www/test2.ttinet",
>>>> ssl => false,
>>>> priority => 10,
>>>> serveraliases => ['test4', 'test3'],
>>>> }
>>>>
>>>> do I change apache::vhost to parameterized classes?
>>>>
>>>> how can I keep array 'form' for parameters, use define and be able to accomplish what I am doing in the flat file arrangement?
>>>>
>>>> (I note that I have been doing a bunch of googling and saw that the recommended method is to 'split' and I know the ruby method split($some_var,",") but I can't envision how this gets done in multiple vhosts and invokes a 'define' and not a class
>> ----
>> OK - downloaded & create_resources into /var/lib/puppet/modules && restarted apache (using passenger so that is where foreman/puppetmaster live)
>
> Hmm, maybe start with smaller steps, make sure create resource is working
>>
>> # cat /var/lib/puppet/yaml/foreman/ubuntu5.ttinet
>> —
>> parameters:
>> puppetmaster: ubuntu.ttinet
>> nginx::vhosts: "name => 'vhost1', port => 8080, docroot => "/var/www/test.ttinet", ssl => false, priority => 10, rails_env => 'development', passenger_enable => 'no', serveraliases => ['test', 'test2']"
>
> Two problems:
> 1. You can't pass the variable to the nginx scope by specifying
> nginx::vhosts, ENC parameters are all top scope, so this is
> effectively ::"nginx::vhosts". If you are using dynamic scoping, just
> use the parameter vhosts and that will get passed to the class
> nginx::vhost.
> 2. This isn't yaml representation of a hash, it's just a string. Use
> irb and to_yaml to get an idea what it should look like:
>
>> puts({'parameters'=>{"key1" => "val1", "hash1" => {"key"=>"val", "key2"=>"val2"}}}.to_yaml)
> —
> parameters:
> hash1:
> key: val
> key2: val2
> key1: val1
>
> Let me know if we can improve the information at:
> https://github.com/puppetlabs/puppetlabs-create_resources
···
On Jul 15, 2011, at 3:20 PM, Nan Liu wrote:
> On Fri, Jul 15, 2011 at 2:59 PM, Craig White wrote:
>> On Jul 15, 2011, at 1:05 PM, Nan Liu wrote:
>>> On Fri, Jul 15, 2011 at 12:34 PM, Craig White wrote:
----
have spent most of the morning on this but still can't seem to figure out the magical incantation.
grep nginx_vhosts yaml/foreman/ubuntu7.ttinet.yaml
nginx_vhosts: "'vhost1' => { 'port' => '8080', 'docroot' => '/var/www/test.ttinet', 'ssl' => 'false', 'priority' => '10', 'rails_env' => 'development', 'passenger_enable' => 'no', 'serveraliases' => ['test', 'test2'] }"
that’s my parameter string
irb…
irb(main):105:0> test = “{‘vhost1’ => { ‘port’ => ‘8080’, ‘docroot’ => ‘/var/www/test.ttinet’, ‘ssl’ => ‘false’, ‘priority’ => ‘10’, ‘rails_env’ => ‘development’, ‘passenger_enable’ => ‘no’, ‘serveraliases’ => [‘test’, ‘test2’] }”
=> "{‘vhost1’ => { ‘port’ => ‘8080’, ‘docroot’ => ‘/var/www/test.ttinet’, ‘ssl’ => ‘false’, ‘priority’ => ‘10’, ‘rails_env’ => ‘development’, ‘passenger_enable’ => ‘no’, ‘serveraliases’ => [‘test’, ‘test2’] }"
irb(main):106:0> test.to_yaml=> “— “{‘vhost1’ => { ‘port’ => ‘8080’, ‘docroot’ => ‘/var/www/test.ttinet’, ‘ssl’ => ‘false’, ‘priority’ => ‘10’, ‘rails_env’ => ‘development’, ‘passenger_enable’ => ‘no’, ‘serveraliases’ => [‘test’, ‘test2’] }”\n”
so class nginx::vhosts (vhosts.pp)
class nginx::vhosts {
create_resources(‘nginx::vhost’, $nginx_vhosts.to_yaml)
}
gives me this error…
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Syntax error at ‘.’; expected ‘)’ at /etc/puppet/modules/nginx/manifests/vhosts.pp:2 on node ubuntu7.ttinet
If I put outer hash braces in parameters…
grep nginx_vhosts yaml/foreman/ubuntu7.ttinet.yaml
nginx_vhosts: “{‘vhost1’ => { ‘port’ => ‘8080’, ‘docroot’ => ‘/var/www/test.ttinet’, ‘ssl’ => ‘false’, ‘priority’ => ‘10’, ‘rails_env’ => ‘development’, ‘passenger_enable’ => ‘no’, ‘serveraliases’ => [‘test’, ‘test2’] }}”
my error becomes…
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class nginx::vhosts in namespaces nginx at /etc/puppet/modules/nginx/manifests/init.pp:2 on node ubuntu7.ttinet
and I have tried it a whole lot of different ways in/out of irb but I keep running into a wall when I try to put it into a class within puppet
Craig