我正在尝试使用Chef在Wordpress多站点前设置Varnish。我是其他人建立的系统的新手,我是一个普通的初学者。
我创建了一个新配方并将其添加到运行列表中,但是当我运行chef-client时,它会执行一个不同的配方来代替我写的那个。具体来说,它运行我的食谱包含的唯一配方。
这是我的食谱,我几乎逐字逐句地复制了我们用于不同网站的预先存在的工作方法:
#
# Cookbook Name:: web_varnish_config
# Recipe:: wordpress
#
include_recipe 'web_varnish_config::default'
all_wordpress_backends = search(:node, "chef_environment:#{node.chef_environment} AND roles:web_wordpress")
all_wordpress_backends.sort_by!{ |n| n[:fqdn] } # Sort the nodes to prevent config-order thrashing.
# Error state
if all_wordpress_backends.empty?
Chef::Log.warn("At least one node with recipes:web_wordpress must exist for chef_environment:#{node.chef_environment}. Skipping Varnish configuration.")
return
end
template "/etc/varnish/default.vcl" do
source "etc/varnish/wordpress.vcl.erb"
mode "0644"
variables(
:all_wordpress_backends => all_wordpress_backends
)
notifies :restart, "service[varnish]", :delayed
end
# Use a share secret for our Varnish instances that is available to our Webservers
# so that Wordpress can clear the Varnish cache.
include_recipe 'chef-vault'
settings = chef_vault_item_for_environment("web_wordpress", "varnish")
if !settings.nil? and settings.key?('secret')
file "/etc/varnish/secret" do
content settings['secret']
mode "0600"
notifies :restart, "service[varnish]", :delayed
end
end
当我运行chef-client时,它运行web_varnish_config :: default而不是这个食谱,web_varnish_config :: wordpress。这就是我的厨师 - 客户端输出的样子(试图复制所有内容,但不能这样,这是开始和结束,我认为最相关):
Starting Chef Client, version 13.6.4
resolving cookbooks for run list: ["yum-epel::default", "serversetup-midd::cent7", "serversetup-midd::rootpassword", "midd_yum_cron::default", "fw-midd::default", "chef-client::config", "chef-client::default", "chef_client_updater::default", "centrify-midd::default", "centrify-midd::sshd", "midd_spacewalk::client", "commvault-midd::default", "serversetup-midd::webserver", "fw-midd::webserver", "centrify-midd::webserver", "chef-vault::default", "ssl-config-midd::miis", "ssl-config-midd::midd", "php-midd::default", "ssl-config-midd::wordpress", "web_php_config", "web_apache_config", "web_apache_config::ssl_context", "web_wordpress", "cookbook_versions::all", "ssl-config-midd::davisfellowsforpeace", "ssl-config-midd::davisprojectsforpeace", "ssl-config-midd::davisuwcscholars", "varnish-midd::default", "fw-midd::varnishserver", "web_varnish_config::backend", "web_varnish_config::wordpress"]
Synchronizing Cookbooks:
- smbfs (0.5.0)
- compat_resource (12.19.0)
- web_php_config (1.1.0)
- ohai (5.1.0)
- midd_spacewalk (0.4.3)
- windows (3.0.5)
- yum (5.0.1)
- firewalld (1.1.5)
- cookbook_versions (1.0.0)
- serversetup-midd (2.6.10)
- commvault-midd (2.3.1)
- cron (4.1.3)
- php-midd (2.0.6)
- ssl-config-midd (2.2.1)
- chef-vault (3.0.0)
- logrotate (2.2.0)
- selinux (2.0.3)
- ssh_authorized_keys (0.4.0)
- chef_client_updater (2.0.3)
- web_wordpress (2.0.10)
- varnish-midd (2.0.3)
- chef-client (8.1.6)
- users (5.1.0)
- yum-epel (2.1.2)
- web_apache_config (2.0.10)
- web_varnish_config (2.3.2)
- sshd (1.3.1)
- fw-midd (3.2.5)
- midd_yum_cron (1.0.0)
- web_sshkeys (1.0.2)
- web_git_tracking_branch (1.1.0)
- centrify-midd (3.1.1)
最后:
Recipe: web_varnish_config::backend
* cookbook_file[/var/www/html/check.html] action create (up to date)
* web_apache_config_vhost[vhost-7-wwwhealthcheck.conf] action create
* template[/etc/httpd/conf.d/vhost-7-wwwhealthcheck.conf] action create (up to date)
(up to date)
# NOTE: Below is where I'm expecting web_varnish_config:wordpress
Recipe: web_varnish_config::default
* service[varnish] action enable (up to date)
* template[/etc/varnish/varnish.params] action create (up to date)
* service[varnishncsa] action enable (up to date)
* service[varnishncsa] action start (up to date)
* cookbook_file[/etc/systemd/system/varnishncsa.service] action create (up to date)
如果我拿出包含行,那么chef-client会完全跳过它,没有错误。
有什么想法吗?
答案 0 :(得分:0)
从评论中复制下来,配方中的搜索很可能不会返回任何节点,因此配方会在写入时自动跳过。
答案 1 :(得分:0)
事实证明我忘了更新角色的名称:
# I needed to change roles:web_wordpress to roles:web_wordpress_new
all_wordpress_backends = search(:node, "chef_environment:#{node.chef_environment} AND roles:web_wordpress")
这意味着我的问题非常具体,可能对其他人没有帮助,但确实如此。