Chef: Install multiple WordPress Site

I am using Chef to deploy WordPress Sites on a single node. I am using a wrapper recipe on top of Supermarkets “WordPress recipe“. I am not sure how to tell my wrapper cookbook to install the wordpress files on multiple directories: Here si the attribute needs to be set to define the install dir

node['wordpress']['dir'] = '<path for the install dir'

I have tried putting this block in default attribute file but it only installs at the last folder not the first 3 folders.

Read More
default['apps'] = ['app1', 'app2, 'app3', 'app4']
default['apps'].each do |app|

    node.default['wordpress']['dir'] = "/home/wordpress-user/#{app}"

end

I also tried something like this in my recipe file

This is how I am trying to create the folders:

 node['apps'].each do |app|
  directory "/home/wordpress-user/#{app}" do
  owner node['wordpress']['user']
  group node['wordpress']['group']
  mode '0755'
  action :create
  Chef::Log.info "App files will be installed under /home/wordpress-user/#{app}"
  not_if { File.exist?("/home/wordpress-user/#{app}")}
  end
end

and then I am trying to tell it to install the wordpress files in a loop

 node.default['apps'].each do |app|
     node.override['wordpress']['dir'] = "/home/wordpress-user/#{app}"
 end

But somehow this is not working. I am sure I am doing something wrong. I am very new to Chef. Please help..

Related posts

1 comment

  1. On your case I would write wordpress recipe from scratch, because what have you described will save attribute node[‘wordpress’][‘dir’] = “/home/wordpress-user/app4”, because it overrides existing attribute.
    Please check out attributes section.

    I would use:

    node.default['apps'].each do |app|
      node.override['wordpress']['dir'][app] = "/home/wordpress-user/#{app}"
    
      directory node['wordpress']['dir'][app] do
        owner node['wordpress']['user']
        group node['wordpress']['group']
        mode '0755'
        action :create
        Chef::Log.info "App files will be installed under /home/wordpress-user/#{app}"
        not_if { File.exist?(node['wordpress']['dir'][app])}
      end
    
      bash "extract wp code to #{app}" do
        cwd node['wordpress']['dir'][app]
        code "tar -zxf #{sourcecode}"
      end
    end
    

    Best regards,
    Alexey

    On your case I would configure each app separately in apache configuration , configuring database and extracting wordpress sources.

Comments are closed.