Chef recipe to clone several git repos to separate folders


I need to clone several git repositories into separate folders (i.e /var/www/repo_name). It seems to me, I can do that with:

<pre class="lang-rb prettyprint-override">git node['git_folder'] do repository node['git_repository'] reference "master" action :sync user "username" end

But how can I give several attributes to one recipe in the role?. Can I somehow use data bags for my needs? Is there any different way?


Here is how you would accomplish it using data bags:

Assuming you have the following data bag structure:

data_bags git_repos repo_1.json repo_2.json

Assuming you have the following data bag item structure:

{ "id": "repo_1", "destination": "/var/www/repo_1", "url": "https://repo.to/clone.git, "revision": "master", "user": "username", "action": "sync" }

The attributes id, destination, and url are required. If revision, user, or action are omitted, default values will be used in the recipe:

<pre class="lang-rb prettyprint-override">data_bag('git_repos').each do |name| repo = data_bag_item('git_repos', name) git repo['destination'] do repository repo['url'] reference repo['revision'] || 'master' user repo['user'] || 'username' action repo['action'] ? repo['action'].to_sym : :sync end end

As you can see, you <em>could</em> use data bags in this instance, but it's unclear to me why you would want to do so. In my opinion, this approach is far less intutive and much more difficult to reason about during debugging.


A recipe contains resource declarations, so just declare multiple resources:

git "/var/www/repo1" do repository https://github.com/myname/repo1.git action :checkout end git "/var/www/repo2" do repository https://github.com/myname/repo2.git action :checkout end git "/var/www/repo3" do repository https://github.com/myname/repo3.git action :checkout end

Some people favour a loop in ruby, I'm reluctant unless the cookbook is being driven (from a databag?). I like clear statements of intent in my chef recipes.


  • Spree category pages in custom rails app
  • group array with sub array
  • how to create\\edit encrypted data bag item from a chef recipe
  • Converting VB6 PropertyBag in .NET
  • Kill rosbag gracefully via kill
  • iOS sharing data between viewcontrollers
  • How to extract text from such type of html source?
  • What RDF patterns can be used to represent components and the percentage they make up?
  • Pickle both class variables and instance variables?
  • Regex takes a long time to complete
  • Python: remove double quotes from JSON dumps
  • Categories and SubCategories
  • Subsetting Data Frame into Multiple Data Frames in Pandas
  • How can I do a 301 redirect from http to https in Wildfly 8.2?
  • Sending dynamic email reminders in Ruby on Rails?
  • Changing Machine Type on Google Cloud
  • wpf: update multiple controls via dispatcher
  • Remove characters after a specific character in column
  • Converting datatype Char to Nvarchar
  • Insert records if not exist SQL Server 2005
  • Getting unread count in Sent Folder using Google Apps Script - GMail
  • Action Pack components in Rails
  • Can my PDF ping my server when it is opened?
  • Using MouseListener to select a range of cells in a grid
  • Two Tables Serving as one Model in Rails
  • Sensibility of combined Maven/Ant+Ivy build management for dual platform Desktop/Android deployment?
  • How to explicitly/implicitly implemented interface members in C++/CLI?
  • Bootstrap (v3.3.4) glyphicons not displayed in IE when refresh page (F5)
  • Pycharm: Marking a folder as 'sources root' is not recursive for subfolders
  • Approximate Order-Preserving Huffman Code
  • Button click event not firing in jQuery
  • OOP Javascript - Is “get property” method necessary?
  • Cancel a live stream “fast motion” catch-up in Flash
  • SVN: Merging two branches together
  • File upload with ng-file-upload throwing error
  • embed rChart in Markdown
  • EntityFramework adding new object to nested object collection
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app