Browse Source

Added conf cookbook to manage the configurations

Juanje Ojeda 12 years ago
commit
8922d32c43
5 changed files with 66 additions and 0 deletions
  1. 19 0
      README.md
  2. 25 0
      libraries/file.rb
  3. 6 0
      metadata.rb
  4. 9 0
      providers/file.rb
  5. 7 0
      resources/file.rb

+ 19 - 0
README.md

@@ -0,0 +1,19 @@
+Description
+===========
+
+This cookbok install a policy of shares (network shared directories) to a specific user of a node.
+
+The cookbook ships the policies and install a script into the node that will make the shares availables by the user.
+
+Requirements
+============
+
+Attributes
+==========
+
+* `node['user']` - Name of the user to apply the policies
+* `node['shares']` - List of shares and mount points
+
+Usage
+=====
+

+ 25 - 0
libraries/file.rb

@@ -0,0 +1,25 @@
+class Chef
+  class Resource
+    class File
+      def include?(str)
+        return false unless ::File.exists?(@path)
+
+        file_content = ::File.open(@path).read
+        if file_content =~ /#{str}/
+          Chef::Log.info("file[#{@path}] contains the string '#{str}'")
+          true
+        else
+          Chef::Log.info("file[#{@path}] doesn't contains the string '#{str}'")
+          false
+        end
+      end
+
+      def replace(str, str2)
+        Chef::Log.info("replacing '#{str}' with '#{str2}' at #{@path}")
+        old_content = ::File.open(@path).read
+        content old_content.gsub(str, str2)
+      end
+    end
+  end
+end
+

+ 6 - 0
metadata.rb

@@ -0,0 +1,6 @@
+maintainer       "Juanje Ojeda"
+maintainer_email "jojeda@emergya.com"
+license          "GPL v2"
+description      "Manage configurations"
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
+version          "0.0.1"

+ 9 - 0
providers/file.rb

@@ -0,0 +1,9 @@
+action :replace do
+  file new_resource.name do
+    replace(new_resource.before, new_resource.after) if include?(new_resource.before)
+    owner new_resource.owner
+    group new_resource.group
+    mode "0644"
+    action :touch
+  end
+end

+ 7 - 0
resources/file.rb

@@ -0,0 +1,7 @@
+action :replace # and possibly more
+
+attribute :name, :kind_of => String, :name_attribute => true
+attribute :owner, :kind_of => String
+attribute :group, :kind_of => String
+attribute :before, :kind_of => String
+attribute :after, :kind_of => String