# Adding Yum Repos in a chef run

**URL:** <https://discourse.chef.io/t/adding-yum-repos-in-a-chef-run/1660>\
**Category:** Chef Infra (archive)\
**Created:** [January 21, 2011, 11:54am UTC](https://discourse.chef.io/t/adding-yum-repos-in-a-chef-run/1660 "2011-01-21T11:54:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haselwanter\_Edmund](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/haselwanter_edmund/32/635_2.png) [@Haselwanter\_Edmund](https://discourse.chef.io/u/Haselwanter_Edmund)\
**Post date:** [January 21, 2011, 11:54am UTC](https://discourse.chef.io/t/adding-yum-repos-in-a-chef-run/1660/1 "2011-01-21T11:54:49Z")

</div>

Hi,

just run in a problem with adding a repo to yum and install a package in the same chef run

simplified version:

if node[:platform] =~ /centos|redhat/i  
#not in default repos  
remote\_file “/etc/yum.repos.d/RubyWorks.repo” do  
source "[http://rubyworks.rubyforge.org/RubyWorks.repo](http://rubyworks.rubyforge.org/RubyWorks.repo)"  
mode "0644"  
action :create\_if\_missing  
end

package “runit” do  
action :install  
end

this fails in the first run

[Thu, 20 Jan 2011 18:48:54 -0500] INFO: remote\_file[/etc/yum.repos.d/RubyWorks.repo]: Creating /etc/yum.repos.d/RubyWorks.repo  
[Thu, 20 Jan 2011 18:48:54 -0500] INFO: Setting mode to 644 for remote\_file[/etc/yum.repos.d/RubyWorks.repo]  
[Thu, 20 Jan 2011 18:48:54 -0500] ERROR: package[runit] (/var/chef-solo/cookbooks/runit/recipes/default.rb:64:in `from_file') had an error: No version specified, and no candidate version available for runit /usr/lib64/ruby/gems/1.8/gems/chef-0.9.8/bin/../lib/chef/provider/package.rb:50:in`action\_install’

but succeeds in the following runs

cu edi

–  
DI Edmund Haselwanter, [edmund@haselwanter.com](mailto:edmund@haselwanter.com), [http://edmund.haselwanter.com/](http://edmund.haselwanter.com/)  
[http://www.iteh.at](http://www.iteh.at) | [http://facebook.com/iTeh.solutions](http://facebook.com/iTeh.solutions) | [http://at.linkedin.com/in/haselwanteredmund](http://at.linkedin.com/in/haselwanteredmund)

---

<div class="post-metadata">

**Author:** ![nukemberg](https://avatars.discourse-cdn.com/v4/letter/n/a9adbd/32.png) [@nukemberg](https://discourse.chef.io/u/nukemberg)\
**Post date:** [January 21, 2011, 12:21pm UTC](https://discourse.chef.io/t/adding-yum-repos-in-a-chef-run/1660/2 "2011-01-21T12:21:01Z")

</div>

Repositories are best installed early, so force the remote\_file resource  
to run at compile time, E.G.:

r = remote\_file "/etc/yum.repos.d/RubyWorks.repo" do  
source "[http://rubyworks.rubyforge.org/RubyWorks.repo](http://rubyworks.rubyforge.org/RubyWorks.repo)"  
mode "0644"  
end

r.run\_action(:create\_if\_missing)

Regards,  
Avishai

On 01/21/2011 01:54 PM, Haselwanter Edmund wrote:

> Hi,
> 
> just run in a problem with adding a repo to yum and install a package in the same chef run
> 
> simplified version:
> 
> if node[:platform] =~ /centos|redhat/i  
> #not in default repos  
> remote\_file "/etc/yum.repos.d/RubyWorks.repo" do  
> source "[http://rubyworks.rubyforge.org/RubyWorks.repo](http://rubyworks.rubyforge.org/RubyWorks.repo)"  
> mode "0644"  
> action :create\_if\_missing  
> end
> 
> package "runit" do  
> action :install  
> end
> 
> this fails in the first run
> 
> [Thu, 20 Jan 2011 18:48:54 -0500] INFO: remote\_file[/etc/yum.repos.d/RubyWorks.repo]: Creating /etc/yum.repos.d/RubyWorks.repo  
> [Thu, 20 Jan 2011 18:48:54 -0500] INFO: Setting mode to 644 for remote\_file[/etc/yum.repos.d/RubyWorks.repo]  
> [Thu, 20 Jan 2011 18:48:54 -0500] ERROR: package[runit] (/var/chef-solo/cookbooks/runit/recipes/default.rb:64:in `from_file') had an error: No version specified, and no candidate version available for runit /usr/lib64/ruby/gems/1.8/gems/chef-0.9.8/bin/../lib/chef/provider/package.rb:50:in `action\_install'
> 
> but succeeds in the following runs
> 
> cu edi
> 
> --  
> DI Edmund Haselwanter, [edmund@haselwanter.com](mailto:edmund@haselwanter.com), [http://edmund.haselwanter.com/](http://edmund.haselwanter.com/)  
> [http://www.iteh.at](http://www.iteh.at) | [Facebook](http://facebook.com/iTeh.solutions) | [http://at.linkedin.com/in/haselwanteredmund](http://at.linkedin.com/in/haselwanteredmund)

---

<div class="post-metadata">

**Author:** ![Haselwanter\_Edmund](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/haselwanter_edmund/32/635_2.png) [@Haselwanter\_Edmund](https://discourse.chef.io/u/Haselwanter_Edmund)\
**Post date:** [January 21, 2011, 12:32pm UTC](https://discourse.chef.io/t/adding-yum-repos-in-a-chef-run/1660/3 "2011-01-21T12:32:11Z")

</div>

On 21.01.2011, at 13:21, Avishai Ish-Shalom wrote:

> Repositories are best installed early, so force the remote\_file resource

Ah. Forgot about that pattern (like with installing and using gems)

> to run at compile time, E.G.:
> 
> r = remote\_file "/etc/yum.repos.d/RubyWorks.repo" do  
> source "[http://rubyworks.rubyforge.org/RubyWorks.repo](http://rubyworks.rubyforge.org/RubyWorks.repo)"  
> mode "0644"  
> end
> 
> r.run\_action(:create\_if\_missing)

many thanks, will try that

> Regards,  
> Avishai
> 
> On 01/21/2011 01:54 PM, Haselwanter Edmund wrote:
> 
> > Hi,
> > 
> > just run in a problem with adding a repo to yum and install a package in the same chef run
> > 
> > simplified version:
> > 
> > if node[:platform] =~ /centos|redhat/i  
> > #not in default repos  
> > remote\_file "/etc/yum.repos.d/RubyWorks.repo" do  
> > source "[http://rubyworks.rubyforge.org/RubyWorks.repo](http://rubyworks.rubyforge.org/RubyWorks.repo)"  
> > mode "0644"  
> > action :create\_if\_missing  
> > end
> > 
> > package "runit" do  
> > action :install  
> > end
> > 
> > this fails in the first run
> > 
> > [Thu, 20 Jan 2011 18:48:54 -0500] INFO: remote\_file[/etc/yum.repos.d/RubyWorks.repo]: Creating /etc/yum.repos.d/RubyWorks.repo  
> > [Thu, 20 Jan 2011 18:48:54 -0500] INFO: Setting mode to 644 for remote\_file[/etc/yum.repos.d/RubyWorks.repo]  
> > [Thu, 20 Jan 2011 18:48:54 -0500] ERROR: package[runit] (/var/chef-solo/cookbooks/runit/recipes/default.rb:64:in `from_file') had an error: No version specified, and no candidate version available for runit /usr/lib64/ruby/gems/1.8/gems/chef-0.9.8/bin/../lib/chef/provider/package.rb:50:in `action\_install'
> > 
> > but succeeds in the following runs
> > 
> > cu edi
> > 
> > --  
> > DI Edmund Haselwanter, [edmund@haselwanter.com](mailto:edmund@haselwanter.com), [http://edmund.haselwanter.com/](http://edmund.haselwanter.com/)  
> > [http://www.iteh.at](http://www.iteh.at) | [Facebook](http://facebook.com/iTeh.solutions) | [http://at.linkedin.com/in/haselwanteredmund](http://at.linkedin.com/in/haselwanteredmund)

--  
DI Edmund Haselwanter, [edmund@haselwanter.com](mailto:edmund@haselwanter.com), [http://edmund.haselwanter.com/](http://edmund.haselwanter.com/)  
[http://www.iteh.at](http://www.iteh.at) | [Facebook](http://facebook.com/iTeh.solutions) | [http://at.linkedin.com/in/haselwanteredmund](http://at.linkedin.com/in/haselwanteredmund)

---

<div class="post-metadata">

**Author:** ![Sean\_OMeara](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/sean_omeara/32/435_2.png) [@Sean\_OMeara](https://discourse.chef.io/u/Sean_OMeara)\
**Post date:** [January 21, 2011, 3:35pm UTC](https://discourse.chef.io/t/adding-yum-repos-in-a-chef-run/1660/4 "2011-01-21T15:35:33Z")

</div>

you have to execute a "yum clean all" or "yum clean headers" after  
adding a repo, otherwise it will use cached data.

-s

On Fri, Jan 21, 2011 at 7:32 AM, Haselwanter Edmund  
[edmund@haselwanter.com](mailto:edmund@haselwanter.com) wrote:

> On 21.01.2011, at 13:21, Avishai Ish-Shalom wrote:
> 
> > Repositories are best installed early, so force the remote\_file resource
> 
> Ah. Forgot about that pattern (like with installing and using gems)
> 
> > to run at compile time, E.G.:
> > 
> > r = remote\_file "/etc/yum.repos.d/RubyWorks.repo" do  
> > source "[http://rubyworks.rubyforge.org/RubyWorks.repo](http://rubyworks.rubyforge.org/RubyWorks.repo)"  
> > mode "0644"  
> > end
> > 
> > r.run\_action(:create\_if\_missing)
> 
> many thanks, will try that
> 
> > Regards,  
> > Avishai
> > 
> > On 01/21/2011 01:54 PM, Haselwanter Edmund wrote:
> > 
> > > Hi,
> > > 
> > > just run in a problem with adding a repo to yum and install a package in the same chef run
> > > 
> > > simplified version:
> > > 
> > > if node[:platform] =~ /centos|redhat/i  
> > > #not in default repos  
> > > remote\_file "/etc/yum.repos.d/RubyWorks.repo" do  
> > > source "[http://rubyworks.rubyforge.org/RubyWorks.repo](http://rubyworks.rubyforge.org/RubyWorks.repo)"  
> > > mode "0644"  
> > > action :create\_if\_missing  
> > > end
> > > 
> > > package "runit" do  
> > > action :install  
> > > end
> > > 
> > > this fails in the first run
> > > 
> > > [Thu, 20 Jan 2011 18:48:54 -0500] INFO: remote\_file[/etc/yum.repos.d/RubyWorks.repo]: Creating /etc/yum.repos.d/RubyWorks.repo  
> > > [Thu, 20 Jan 2011 18:48:54 -0500] INFO: Setting mode to 644 for remote\_file[/etc/yum.repos.d/RubyWorks.repo]  
> > > [Thu, 20 Jan 2011 18:48:54 -0500] ERROR: package[runit] (/var/chef-solo/cookbooks/runit/recipes/default.rb:64:in `from_file') had an error: No version specified, and no candidate version available for runit /usr/lib64/ruby/gems/1.8/gems/chef-0.9.8/bin/../lib/chef/provider/package.rb:50:in `action\_install'
> > > 
> > > but succeeds in the following runs
> > > 
> > > cu edi
> > > 
> > > --  
> > > DI Edmund Haselwanter, [edmund@haselwanter.com](mailto:edmund@haselwanter.com), [http://edmund.haselwanter.com/](http://edmund.haselwanter.com/)  
> > > [http://www.iteh.at](http://www.iteh.at) | [Facebook](http://facebook.com/iTeh.solutions) | [http://at.linkedin.com/in/haselwanteredmund](http://at.linkedin.com/in/haselwanteredmund)
> 
> --  
> DI Edmund Haselwanter, [edmund@haselwanter.com](mailto:edmund@haselwanter.com), [http://edmund.haselwanter.com/](http://edmund.haselwanter.com/)  
> [http://www.iteh.at](http://www.iteh.at) | [Facebook](http://facebook.com/iTeh.solutions) | [http://at.linkedin.com/in/haselwanteredmund](http://at.linkedin.com/in/haselwanteredmund)

---

<div class="post-metadata">

**Author:** ![Matt\_Ray\_OPSCODE](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/matt_ray_opscode/32/459_2.png) [@Matt\_Ray\_OPSCODE](https://discourse.chef.io/u/Matt_Ray_OPSCODE)\
**Post date:** [January 21, 2011, 5:10pm UTC](https://discourse.chef.io/t/adding-yum-repos-in-a-chef-run/1660/5 "2011-01-21T17:10:00Z")

</div>

It's probably worthwhile to put together a yum cookbook, similar to  
the apt one that provides an LWRP for adding external repositories.  
It's on my list of things to get to eventually, but if it's a more  
pressing concern please jump on that.

Thanks,  
Matt Ray  
Technical Evangelist | Opscode, Inc  
E: [matt@opscode.com](mailto:matt@opscode.com) T: (512) 731-2218  
Twitter, Github: mattray

On Fri, Jan 21, 2011 at 9:35 AM, Sean OMeara [someara@gmail.com](mailto:someara@gmail.com) wrote:

> you have to execute a "yum clean all" or "yum clean headers" after  
> adding a repo, otherwise it will use cached data.
> 
> -s
> 
> On Fri, Jan 21, 2011 at 7:32 AM, Haselwanter Edmund  
> [edmund@haselwanter.com](mailto:edmund@haselwanter.com) wrote:
> 
> > On 21.01.2011, at 13:21, Avishai Ish-Shalom wrote:
> > 
> > > Repositories are best installed early, so force the remote\_file resource
> > 
> > Ah. Forgot about that pattern (like with installing and using gems)
> > 
> > > to run at compile time, E.G.:
> > > 
> > > r = remote\_file "/etc/yum.repos.d/RubyWorks.repo" do  
> > > source "[http://rubyworks.rubyforge.org/RubyWorks.repo](http://rubyworks.rubyforge.org/RubyWorks.repo)"  
> > > mode "0644"  
> > > end
> > > 
> > > r.run\_action(:create\_if\_missing)
> > 
> > many thanks, will try that
> > 
> > > Regards,  
> > > Avishai
> > > 
> > > On 01/21/2011 01:54 PM, Haselwanter Edmund wrote:
> > > 
> > > > Hi,
> > > > 
> > > > just run in a problem with adding a repo to yum and install a package in the same chef run
> > > > 
> > > > simplified version:
> > > > 
> > > > if node[:platform] =~ /centos|redhat/i  
> > > > #not in default repos  
> > > > remote\_file "/etc/yum.repos.d/RubyWorks.repo" do  
> > > > source "[http://rubyworks.rubyforge.org/RubyWorks.repo](http://rubyworks.rubyforge.org/RubyWorks.repo)"  
> > > > mode "0644"  
> > > > action :create\_if\_missing  
> > > > end
> > > > 
> > > > package "runit" do  
> > > > action :install  
> > > > end
> > > > 
> > > > this fails in the first run
> > > > 
> > > > [Thu, 20 Jan 2011 18:48:54 -0500] INFO: remote\_file[/etc/yum.repos.d/RubyWorks.repo]: Creating /etc/yum.repos.d/RubyWorks.repo  
> > > > [Thu, 20 Jan 2011 18:48:54 -0500] INFO: Setting mode to 644 for remote\_file[/etc/yum.repos.d/RubyWorks.repo]  
> > > > [Thu, 20 Jan 2011 18:48:54 -0500] ERROR: package[runit] (/var/chef-solo/cookbooks/runit/recipes/default.rb:64:in `from_file') had an error: No version specified, and no candidate version available for runit /usr/lib64/ruby/gems/1.8/gems/chef-0.9.8/bin/../lib/chef/provider/package.rb:50:in `action\_install'
> > > > 
> > > > but succeeds in the following runs
> > > > 
> > > > cu edi
> > > > 
> > > > --  
> > > > DI Edmund Haselwanter, [edmund@haselwanter.com](mailto:edmund@haselwanter.com), [http://edmund.haselwanter.com/](http://edmund.haselwanter.com/)  
> > > > [http://www.iteh.at](http://www.iteh.at) | [Facebook](http://facebook.com/iTeh.solutions) | [http://at.linkedin.com/in/haselwanteredmund](http://at.linkedin.com/in/haselwanteredmund)
> > 
> > --  
> > DI Edmund Haselwanter, [edmund@haselwanter.com](mailto:edmund@haselwanter.com), [http://edmund.haselwanter.com/](http://edmund.haselwanter.com/)  
> > [http://www.iteh.at](http://www.iteh.at) | [Facebook](http://facebook.com/iTeh.solutions) | [http://at.linkedin.com/in/haselwanteredmund](http://at.linkedin.com/in/haselwanteredmund)

---

<div class="post-metadata">

**Author:** ![James\_Casey](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/james_casey/32/847_2.png) [@James\_Casey](https://discourse.chef.io/u/James_Casey)\
**Post date:** [January 21, 2011, 6:55pm UTC](https://discourse.chef.io/t/adding-yum-repos-in-a-chef-run/1660/6 "2011-01-21T18:55:50Z")

</div>

Hey Matt,

I've got the starting of this, along with the pieces to configure a  
yum repo server. I'll try and put it together and submit it back  
upstream.

cheers,

## James.

On 21 January 2011 18:10, Matt Ray [matt@opscode.com](mailto:matt@opscode.com) wrote:

> It's probably worthwhile to put together a yum cookbook, similar to  
> the apt one that provides an LWRP for adding external repositories.  
> It's on my list of things to get to eventually, but if it's a more  
> pressing concern please jump on that.
> 
> Thanks,  
> Matt Ray  
> Technical Evangelist | Opscode, Inc  
> E: [matt@opscode.com](mailto:matt@opscode.com) T: (512) 731-2218  
> Twitter, Github: mattray
> 
> On Fri, Jan 21, 2011 at 9:35 AM, Sean OMeara [someara@gmail.com](mailto:someara@gmail.com) wrote:
> 
> > you have to execute a "yum clean all" or "yum clean headers" after  
> > adding a repo, otherwise it will use cached data.
> > 
> > -s
> > 
> > On Fri, Jan 21, 2011 at 7:32 AM, Haselwanter Edmund  
> > [edmund@haselwanter.com](mailto:edmund@haselwanter.com) wrote:
> > 
> > > On 21.01.2011, at 13:21, Avishai Ish-Shalom wrote:
> > > 
> > > > Repositories are best installed early, so force the remote\_file resource
> > > 
> > > Ah. Forgot about that pattern (like with installing and using gems)
> > > 
> > > > to run at compile time, E.G.:
> > > > 
> > > > r = remote\_file "/etc/yum.repos.d/RubyWorks.repo" do  
> > > > source "[http://rubyworks.rubyforge.org/RubyWorks.repo](http://rubyworks.rubyforge.org/RubyWorks.repo)"  
> > > > mode "0644"  
> > > > end
> > > > 
> > > > r.run\_action(:create\_if\_missing)
> > > 
> > > many thanks, will try that
> > > 
> > > > Regards,  
> > > > Avishai
> > > > 
> > > > On 01/21/2011 01:54 PM, Haselwanter Edmund wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > just run in a problem with adding a repo to yum and install a package in the same chef run
> > > > > 
> > > > > simplified version:
> > > > > 
> > > > > if node[:platform] =~ /centos|redhat/i  
> > > > > #not in default repos  
> > > > > remote\_file "/etc/yum.repos.d/RubyWorks.repo" do  
> > > > > source "[http://rubyworks.rubyforge.org/RubyWorks.repo](http://rubyworks.rubyforge.org/RubyWorks.repo)"  
> > > > > mode "0644"  
> > > > > action :create\_if\_missing  
> > > > > end
> > > > > 
> > > > > package "runit" do  
> > > > > action :install  
> > > > > end
> > > > > 
> > > > > this fails in the first run
> > > > > 
> > > > > [Thu, 20 Jan 2011 18:48:54 -0500] INFO: remote\_file[/etc/yum.repos.d/RubyWorks.repo]: Creating /etc/yum.repos.d/RubyWorks.repo  
> > > > > [Thu, 20 Jan 2011 18:48:54 -0500] INFO: Setting mode to 644 for remote\_file[/etc/yum.repos.d/RubyWorks.repo]  
> > > > > [Thu, 20 Jan 2011 18:48:54 -0500] ERROR: package[runit] (/var/chef-solo/cookbooks/runit/recipes/default.rb:64:in `from_file') had an error: No version specified, and no candidate version available for runit /usr/lib64/ruby/gems/1.8/gems/chef-0.9.8/bin/../lib/chef/provider/package.rb:50:in `action\_install'
> > > > > 
> > > > > but succeeds in the following runs
> > > > > 
> > > > > cu edi
> > > > > 
> > > > > --  
> > > > > DI Edmund Haselwanter, [edmund@haselwanter.com](mailto:edmund@haselwanter.com), [http://edmund.haselwanter.com/](http://edmund.haselwanter.com/)  
> > > > > [http://www.iteh.at](http://www.iteh.at) | [http://facebook.com/iTeh.solutions](http://facebook.com/iTeh.solutions) | [http://at.linkedin.com/in/haselwanteredmund](http://at.linkedin.com/in/haselwanteredmund)
> > > 
> > > --  
> > > DI Edmund Haselwanter, [edmund@haselwanter.com](mailto:edmund@haselwanter.com), [http://edmund.haselwanter.com/](http://edmund.haselwanter.com/)  
> > > [http://www.iteh.at](http://www.iteh.at) | [http://facebook.com/iTeh.solutions](http://facebook.com/iTeh.solutions) | [http://at.linkedin.com/in/haselwanteredmund](http://at.linkedin.com/in/haselwanteredmund)
