Class: ForemanUsers::Syuser
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ForemanUsers::Syuser
- Defined in:
- app/models/foreman_users/syuser.rb
Instance Method Summary collapse
- #create_content ⇒ Object
-
#create_dir ⇒ Object
after_destory :destory_dir.
- #destory_dir ⇒ Object
Instance Method Details
#create_content ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/foreman_users/syuser.rb', line 56 def create_content #content = "class users { " + "\n" + "\s\s" + "include baseline::params" + "\n" + "\s\s" + "@user {'$user':" + "\n" + "\s\s\s\s" + "ensure => $user_ensure," + "\n" + "\s\s\s\s" + "home => $user_home," + "\n" + "\s\s" + "}" + "\n" + "}" # user_content = "class users {" + "\n" + "\s\s" + "user { '" + self.name + "':" + "\n\s\s\s\s" + "ensure => '" + self.ensure + "'," + "\n\s\s\s\s" + "gid => '" + self.gid + "'," + "\n\s\s\s\s" + "groups => [" + self.groups + "]," + "\n\s\s\s\s" + "home => '" + self.home + "'," + "\n\s\s\s\s" + "password => '" + self.password + "'," + "\n\s\s\s\s" + "password_max_age => '" + self.password_max_age + "'," + "\n\s\s\s\s" + "password_min_age => '" + self.password_min_age + "'," + "\n\s\s\s\s" + "shell => '" + self.shell + "'," + "\n\s\s\s\s" + "uid => '" + self.uid + "'," + "\n\s\s" +"}" + "\n" group_content = "\s\s" if self.sygroups.size > 0 self.sygroups.each do |sygroup| group_content += "group {'"+ sygroup.name + "':" + "\n\s\s\s\s" + "ensure => '" + sygroup.ensure + "'," + "\n\s\s\s\s" + "gid => '" + sygroup.gid + "'," + "\n\s\s" +"}" + "\n\s\s" end end rs = user_content + group_content + "\n" + "}" return rs end |
#create_dir ⇒ Object
after_destory :destory_dir
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/foreman_users/syuser.rb', line 12 def create_dir #目前用 "/home/stdtnt/app/"代替 "/etc/puppet/environments/production/modules/users" #该处需要注意权限问题,当前用户是否具有该目录的操作权限 root_dir_name = "/etc/puppet/environments/production/modules/users" #self.destory_dir #默认删除该目录,然后重新创建 dir_exist_status = File.exist?(root_dir_name) #判断该目录是否存在 if !dir_exist_status #创建目录结构 Dir::mkdir(root_dir_name) if !File.exist?(root_dir_name + "/files") Dir::mkdir(root_dir_name + "/files") end if !File.exist?(root_dir_name + "/manifests") Dir::mkdir(root_dir_name + "/manifests") end #生成files下welcome.conf文件 files_welcome_File = File.new(root_dir_name + "/files/welcome.conf", "w+") files_welcome_File.close #生成manifests下init.pp文件 main_init_File = File.new(root_dir_name +"/manifests/init.pp", "w+") if main_init_File main_init_File.syswrite(self.create_content) else puts "Unable to open file!" end main_init_File.close end end |
#destory_dir ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/foreman_users/syuser.rb', line 44 def destory_dir #目前用 "/home/stdtnt/app/"代替 "/etc/puppet/environments/production/modules/users" #该处需要注意权限问题,当前用户是否具有该目录的操作权限 root_dir_name = "/etc/puppet/environments/production/modules/users" #判断该目录是否存在 dir_exist_status = File.exist?(root_dir_name ) if dir_exist_status #使用fileUtils.rm_r 删除该文件夹及其以下所有内容 FileUtils.rm_r root_dir_name end end |