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.
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..
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.