To install logstash with rpm (https://www.elastic.co/guide/en/logstash/current/installing-logstash.html) I need to manually specify the baseurl and the pgpkey
I can't see these options in the chef docs (https://docs.chef.io/resource_rpm_package.html)
Is there a way to do this with chef?
You can try with "yum_repository" resource. For, example:-
Github Source:- https://github.com/chef-cookbooks/yum
# add the Zenoss repository
yum_repository 'zenoss' do
description "Zenoss Stable repo"
baseurl "http://dev.zenoss.com/yum/stable/"
gpgkey 'http://dev.zenoss.com/yum/RPM-GPG-KEY-zenoss'
action :create
end
Related
Locally, we use a private source URL for our poetry configurations, and the credentials will be found in our pip.ini. However, in our CI/CD pipeline we obtain a secret which changes the PIP_EXTRA_INDEX_URL. This is not enough, because we need to change the pyproject.toml (see below) with this URL.
[[tool.poetry.source]]
name = "private"
url = "https://someplace.pkgs.visualstudio.com/_packaging/somewhere/pypi/simple/"
secondary = true
This is not changed with poetry config repositories.private "$PIP_EXTRA_INDEX_URL". How should we change this then?
You can just the link without the credentials and specify the login like this:
poetry config repositories.someplace https://someplace.pkgs.visualstudio.com/_packaging/somewhere/pypi/
poetry config http-basic.someplace someuser $(personal-access-token)
Problem is that chef tries to install template first, and only then installs packages. If i comment template block, chef will install sphinxsearch package fine.
But if template block is not commented, sphinxsearch package is not installed, and chef fails with error
resource template[/etc/sphinxsearch/sphinx.conf] is configured to notify resource service[sphinxsearch] with action reload, but service[sphinxsearch] cannot be found in the resource collection`
Why this happens?
##
# Install system packages
##
node['website']['packages'].each do |pkg|
log 'Installing ' + pkg
package pkg
end
##
# Configure sphinx
##
template "/etc/sphinxsearch/sphinx.conf" do
source 'sphinx.erb'
owner 'root'
group 'root'
mode 00644
notifies :reload, 'service[sphinxsearch]', :delayed
end
notifies and subscribes in chef are both trying to reach out to resources that have been defined in your chef run. They will then call teh indicated action on those resources. In your case:
notifies :reload, 'service[sphinxsearch]', :delayed
is looking for a resource of type service named sphinxsearch and call the reload action on it. If, at the end of the resource gathering (compile) phase, chef cannot find a service[sphinxsearch] resource, then it throws the error. You don't see the package installed because chef never enters the execution phase. (See this answer for more on the two phase nature of chef)
As indicated by #IsabelHM, you could solve the problem by adding
service 'sphinxsearch' do
action [:enable, :start]
end
I suggest you use [:enable, :start] rather than :nothing as this will ensure that the service is always running, even if your template doesn't change. Also, please note that the service resource does not add a service config for you. So if the sphinxsearch package does not add a service config, you'll also need a cookbook_file, template, or remote_file resource to create the service config with.
Add this in your recipe.
service 'sphinxsearch' do
action :nothing
end
I am trying to create a recipe to deploy an application.
I would like to combine the Chef deploy resource with the Chef Mercurial provider. The readme of this provider suggest that it is easy to use with deploy resource. However, I'm not sure how to do this.
The mercurial resource is working as expected:
mercurial deploy[:deploy_to] do
repository deploy[:scm][:repository]
ssh_key "/home/vagrant/.ssh/authorized_keys"
ssh_ignore true
branch true
revision deploy[:scm][:revision]
user deploy[:user]
group deploy[:group]
action :sync
end
However I'm having trouble with the provider
deploy deploy[:deploy_to] do
repository deploy[:scm][:repository]
user deploy[:user]
group deploy[:group]
revision deploy[:scm][:revision]
environment deploy[:environment].to_hash
scm_provider Chef::Provider::Mercurial
action :deploy
end
The error I'm getting is NoMethodError: undefined method 'ssh_key' for Chef::Resource::Deploy. This is probably due to the fact that the resource requires the ssh_key attribute. I don't know how to pass this attribute through when using the deploy resource.
How can I make this work?
Does anyone have an example of how to use the Chef deploy resource with the Chef Mercurial provider?
I am trying to use "elasticsearch/cookbook-elasticsearch" cookbook for with my wrapper cookbook. I want to override following default attributes from cookbook-elasticsearch in my wrapper cookbook.
default.elasticsearch[:rpm_url] = "https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.12.noarch.rpm"
default.elasticsearch[:rpm_sha] = "ab7ea2e00d8f1b73642e3ea44d9647b11e6b0b96"
Cookbook : https://github.com/elasticsearch/cookbook-elasticsearch
How do I do this in my-elasticsearch cookbook ?
cat site-cookbooks/my-elasticsearch/attributes/default.rb
override.elasticsearch[:rpm_url] = "https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.4.noarch.rpm"
override.elasticsearch[:rpm_sha] = "ec8b41c54a6d897479645b2507476e0824bc71db"
is this correct one ?
I want to use this cookbook for chef 10
any help
To add information to #mark-oconnor comment:
Documentation about attributes in chef 10.
Recommended notation would be override['elasticsearch']['rpm_url'] = "new_value" the method and symbol way to access attributes have been problematic in the past.
As the cookbook loading order in chef 10 is not always clearly predictable you have to use override level to ensure the correct value is used when compîling recipes.
Edit after comments:
In the elasticsearch cookbook in version 0.3.13 the default recipe install from tarball.
If you wish to use a packaged install you have to call the corresponding recipe before the default, as in the default recipe there's a guard to not install tarball if elasticsearch is already installed.
The correct recipe in wrapper cookbook for this particular case is:
include_recipe 'elasticsearch::rpm' # Take the overriden attributes and install package
include_recipe 'elasticsearch' # no need to ::default, if omitted it's the recipe loaded
I'm working on a infrastructure where some servers don't have access to the internet, so I have to push the packages to the local repo before declaring them to be installed on Chef.
However we've been on a situation where Chef failed to install a package since the package wasn't there on some boxes and it has been successful on some other boxes.
What I want to do is to run a Ruby/RSpec test before applying Chef config on the nodes to make sure the packages declared on the recipes do actually exist on the repo.
In order to do that I need to be able to list all the packages exists in the our recipes.
My question is: Is there anyway to list all the declared packages in Chef? I had a quick look at Chef::Platform and ChefSpec but unfortunately couldn't find anything useful to my problem.
Do you have any idea where is the best place to look at?
If you use ChefSpec you can find all the packages by calling chef_run.find_resources(:package) inside some test. See the source code. Like this:
require 'chefspec'
describe 'example::default' do
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
it 'does something' do
chef_run.find_resources(:package)...
end
end
You could install one or more of the community ohai plugins. For example the following will return information about installed sofware:
debian
Redhat
windows
Once the plugins are enabled they will add additional node attributes that will be searchable from chef-server.