FAQ
Hello All,

I am trying to create a bunch of apache .conf files by reading data from
a database. My script returns a list of values from the database in YAML
form:

---
classes:
- apache
- dummy
parameters:
domains: 'domains1,domains2,domains3'
puppet_server: dist
users: 'user1, user2'


and I'd like to pass the domains and users arrays to a definition:

define vhostvirt() {
file { "/tmp/${wpdomain}":
#content => template("apache/vhost.conf.erb"),
owner => 'root',
group => 'root',
mode => '777',
ensure => present,
}
}

to create the domain.conf files for me. Unfortunately, I cannot figure
out the correct syntax and aprroach to solving this problem.

Could somebody help please ?

Thanks!


Stoyan

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Search Discussions

  • Stephen Gran at Sep 18, 2012 at 3:28 pm
    Hi,
    On Tue, 2012-09-18 at 19:44 +0500, Stoyan Petkov wrote:
    Hello All,

    I am trying to create a bunch of apache .conf files by reading data
    from a database. My script returns a list of values from the database
    in YAML form:

    ---
    classes:
    - apache
    - dummy
    parameters:
    domains: 'domains1,domains2,domains3'
    puppet_server: dist
    users: 'user1, user2'
    That looks like just a comma-separated string being returned, which is
    fine. We need an array to do what you want, however, so something like:

    $vhost_list = split($domains, ',')

    vhostvirt { $vhost_list: }


    This will create one vhostvirt for each entry in $domains.

    Cheers,
    --
    Stephen Gran
    Senior Systems Integrator - guardian.co.uk

    Please consider the environment before printing this email.
    ------------------------------------------------------------------
    Visit guardian.co.uk - newspaper of the year

    www.guardian.co.uk www.observer.co.uk www.guardiannews.com

    On your mobile, visit m.guardian.co.uk or download the Guardian
    iPhone app www.guardian.co.uk/iphone and iPad edition www.guardian.co.uk/iPad

    Save up to 37% by subscribing to the Guardian and Observer - choose the papers you want and get full digital access.
    Visit guardian.co.uk/subscribe

    ---------------------------------------------------------------------
    This e-mail and all attachments are confidential and may also
    be privileged. If you are not the named recipient, please notify
    the sender and delete the e-mail and all attachments immediately.
    Do not disclose the contents to another person. You may not use
    the information for any purpose, or store, or copy, it in any way.

    Guardian News & Media Limited is not liable for any computer
    viruses or other material transmitted with or as part of this
    e-mail. You should employ virus checking software.

    Guardian News & Media Limited

    A member of Guardian Media Group plc
    Registered Office
    PO Box 68164
    Kings Place
    90 York Way
    London
    N1P 2AP

    Registered in England Number 908396

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Stoyan Petkov at Sep 18, 2012 at 5:15 pm
    Thanks Stephen! That did the trick (although I tried it a few times but
    to no avail.), however, I now see that I didn't describe the whole picture.

    The definition seems ok but the template contains:

    <VirtualHost *:80>
    ServerName <%= name %>
    ServerAlias www.<%= name %>
    DocumentRoot /home/<%= name %>/public_html
    SuexecUserGroup <%= user %> <%= user %>
    <Directory "<%= docroot %>" >
    AllowOverride None
    Order allow,deny
    Allow from all
    Options +SymlinksIfOwnerMatch +Includes
    </Directory>
    ErrorLog /var/log/httpd/<%= user %>/wp_domain-error_log
    CustomLog /var/log/httpd/<%= user %>/wp_domain-access_log combined
    CustomLog /var/log/httpd/<%= user %>/wp_domain-bytes_log "%I %O"
    </VirtualHost>


    and for each domain I'd like to match a user, effectively passing an
    associative array to the definition:

    ---
    classes:
    - apache
    - dummy
    parameters:
    puppet_server: dist
    vhost_info: "'domains1=>user1','domains2=>user2','domains3=>user3'"


    Is that doable in puppet ?

    Thanks!
    On 09/18/2012 08:22 PM, Stephen Gran wrote:
    Hi,
    On Tue, 2012-09-18 at 19:44 +0500, Stoyan Petkov wrote:
    Hello All,

    I am trying to create a bunch of apache .conf files by reading data
    from a database. My script returns a list of values from the database
    in YAML form:

    ---
    classes:
    - apache
    - dummy
    parameters:
    domains: 'domains1,domains2,domains3'
    puppet_server: dist
    users: 'user1, user2'
    That looks like just a comma-separated string being returned, which is
    fine. We need an array to do what you want, however, so something like:

    $vhost_list = split($domains, ',')

    vhostvirt { $vhost_list: }


    This will create one vhostvirt for each entry in $domains.

    Cheers,
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Stephen Gran at Sep 18, 2012 at 4:52 pm
    Hi,
    On Tue, 2012-09-18 at 21:26 +0500, Stoyan Petkov wrote:
    Thanks Stephen! That did the trick (although I tried it a few times but
    to no avail.), however, I now see that I didn't describe the whole picture.

    The definition seems ok but the template contains: ...
    and for each domain I'd like to match a user, effectively passing an
    associative array to the definition:

    ---
    classes:
    - apache
    - dummy
    parameters:
    puppet_server: dist
    vhost_info: "'domains1=>user1','domains2=>user2','domains3=>user3'"


    Is that doable in puppet ?
    Nearly. The problem you'll run into is that, since there are no loop
    iterators in the puppet DSL (why, oh why, still?) you end up not being
    able to do something like:

    virt_host { $array: user => $hash[$name] }

    (where $name is the array entry, and you can dynamically pluck it out of
    the hash as you go). That would be nice, but no.

    You'll have to do something like pass the associative array to the
    define, and in the define pull back the values to be used in the
    template based on the key $name. Something like:

    define vhostvirt($data) {

    $user = $data[$name]
    $docroot = $data[$name]

    file { "/tmp/${name}":
    #content => template("apache/vhost.conf.erb"),
    owner => 'root',
    group => 'root',
    mode => '777',
    ensure => present,
    }
    }

    That should be enough to get you going.

    Good luck,
    --
    Stephen Gran
    Senior Systems Integrator - guardian.co.uk

    Please consider the environment before printing this email.
    ------------------------------------------------------------------
    Visit guardian.co.uk - newspaper of the year

    www.guardian.co.uk www.observer.co.uk www.guardiannews.com

    On your mobile, visit m.guardian.co.uk or download the Guardian
    iPhone app www.guardian.co.uk/iphone and iPad edition www.guardian.co.uk/iPad

    Save up to 37% by subscribing to the Guardian and Observer - choose the papers you want and get full digital access.
    Visit guardian.co.uk/subscribe

    ---------------------------------------------------------------------
    This e-mail and all attachments are confidential and may also
    be privileged. If you are not the named recipient, please notify
    the sender and delete the e-mail and all attachments immediately.
    Do not disclose the contents to another person. You may not use
    the information for any purpose, or store, or copy, it in any way.

    Guardian News & Media Limited is not liable for any computer
    viruses or other material transmitted with or as part of this
    e-mail. You should employ virus checking software.

    Guardian News & Media Limited

    A member of Guardian Media Group plc
    Registered Office
    PO Box 68164
    Kings Place
    90 York Way
    London
    N1P 2AP

    Registered in England Number 908396

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedSep 18, '12 at 2:41p
activeSep 18, '12 at 5:15p
posts4
users2
websitepuppetlabs.com

2 users in discussion

Stoyan Petkov: 2 posts Stephen Gran: 2 posts

People

Translate

site design / logo © 2022 Grokbase