Ask Your Question
0

How to create an array of a lists of files

asked 2014-08-06 09:37:09 -0500

RobN gravatar image

I am sure this is obvious but I cannot seem to find it in all my searches. I need to create an array of a list of files. The list of files are under puppet in a separate module. So I have wrote a basic little routine to a2ensite the array.

 exec { "/usr/sbin/a2ensite $name":
          unless => "/bin/readlink -e /etc/apache2/sites-enabled/$name",
          notify => Exec['reload-apache2'],
        }
and I want to pass it an array from a list of files found in puppet://modules/system/php/common/etc/apache2/sites-available (which is populated under the system/files modules)

edit retag flag offensive close merge delete

Comments

Currently I call it like the following

$php_sites = [ 'asia', 'br', 'cdn', 'ch' ]  
apache2::site {
    $php_sites: ensure => present,
  }  
If I have to hard code $php_sites then every time one of the web team adds a new site I have to change my puppet code, and that is not possible in our environment. Instead if they simply add a file to sites available I want the next puppet run to automatically grab the new file and ae2ensite it.

RobN gravatar imageRobN ( 2014-08-06 10:48:50 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-08-07 03:19:50 -0500

Hi RobN

To answer your question, I need more information from you..

how does your web team adds a new site? manually at for example /var/www (over FTP / SSH) and after that the site should be enabled? do you use an Apache module from forge.puppetlabs?

Hint: Do you know the benefits from hiera? I would recommend you, to revise your workflow:

rewrite your modules and use hiera with for example .yaml files: you (or better your web team) can create whole sites with a simple hash:

apache::vhost:
  'www.puppetlabs.com':
    www_root: '/var/www/www.puppetlabs.com'
    port: '80'

etc etc

back to your question:

"The list of files are under puppet in a separate module" could you please explain that? do you have a file "asia", a file "br" etc in a module directory? (path: system/files) how should that work if you've more then one node?

edit flag offensive delete link more

Comments

Hiera and creating a whole sites aren't what I need to do though. I have looked at Hiera and will implement that in the future, after I get past my current hurdle.
'do you have a file "asia", a file "br" etc' Yes that are on the puppet master. There are 12 nodes not just one. So i have a directory common/ and a directory common-development/ with a list of files. But that really is not my question.
Essentially my question is how to I get a listing of files? So say on a Debian puppet master I wanted a list of the /tmp/fileslist/* which contains 10 text files name 'a' through 'j' then how would I get an array from that that contained each file name as an element?

$file_array=['a', 'b', 'c', ... , 'j' ]

RobN gravatar imageRobN ( 2014-08-07 06:44:52 -0500 )edit

Oh and I have downloaded the forge Apache module but it was overly complicated and seemed to break our environment so I had to write a much more basic one that works for us.

RobN gravatar imageRobN ( 2014-08-07 08:17:28 -0500 )edit

Oh and as far as I know the developers would simply in the git repo add a new file (say "com") to /etc/apache2/sites-available/, so I use puppet to replicate the repo to all the web servers, but then I need to go in and automatically

a2ensite com

RobN gravatar imageRobN ( 2014-08-07 12:28:09 -0500 )edit
0

answered 2014-08-08 09:52:52 -0500

RobN gravatar image

I believe that since each puppet run is on the client that the answer is simply puppet does not have that ability, unless some magic is written to ssh back to the server each time to display the contents of the directory to know whether or not a new site or module needs to be added.

I guess my question should be is it possible to have the web team add sites and modules without touching puppet code? Answer from what I can tell (though I am a puppet newb) is no, which is a real sad thing as I would think other companies want IT to run the puppet code and web team to run the web design. But maybe I am wrong, if so please let me know how...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-08-06 09:37:09 -0500

Seen: 646 times

Last updated: Aug 08 '14