# yum\_repository module (has anyone thought of doing it...)

**URL:** <https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630>\
**Category:** Ansible Project\
**Created:** [April 5, 2013, 8:18am UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630 "2013-04-05T08:18:37Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jimmy\_Tang](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@Jimmy\_Tang](https://forum.ansible.com/u/Jimmy_Tang)\
**Post date:** [April 5, 2013, 8:18am UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/1 "2013-04-05T08:18:37Z")

</div>

Hi All

I just noticed that I wanted to run ‘yum-conf-manager’ to add [http://ftp1.scientificlinux.org/linux/scientific/6.4/x86\_64/addons/mock-sl6-config/](http://ftp1.scientificlinux.org/linux/scientific/6.4/x86_64/addons/mock-sl6-config/) to my SL machines for testing and realised that there is probably a need for creating a yum\_repository module that takes a url and adds/removes it on the managed machine (state=present,absent). Other useful things might include states=enabled,disabled as well to toggle the availability of packages from different repos. I’m not sure if you would want to have functionality like supporting adding/removing repo files though as you could just do that with the stock copy/template modules.

Jimmy.

---

<div class="post-metadata">

**Author:** ![Seth\_Vidal](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@Seth\_Vidal](https://forum.ansible.com/u/Seth_Vidal)\
**Post date:** [April 5, 2013, 1:48pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/2 "2013-04-05T13:48:03Z")

</div>

But a yum repository is just a simple file. Why not just use copy or  
template or even get\_url?

-sv

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [April 5, 2013, 3:50pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/3 "2013-04-05T15:50:24Z")

</div>

I concur, I would almost always just template these into yum.repos.d

---

<div class="post-metadata">

**Author:** ![Tin\_Tvrtkovic](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@Tin\_Tvrtkovic](https://forum.ansible.com/u/Tin_Tvrtkovic)\
**Post date:** [April 5, 2013, 10:04pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/4 "2013-04-05T22:04:24Z")

</div>

This might not be helpful for you, but can you get an RPM for the repo? I just do this:

> `<br> - name: ensure PGDG Yum repo is installed<br><br>`  
>   
> |
> 
> - |  
>   
>   
> `<br> shell: rpm -Uvh http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm <br><br>`  
>   
> |  
>   
>   
> `<br> creates=/etc/yum.repos.d/pgdg-92-centos.repo<br><br>`  
>   
> |

(being a little lazy there with using shell instead of command and the useless flags to rpm, but who cares)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 6, 2013, 12:11am UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/5 "2013-04-06T00:11:09Z")

</div>

not a bad trick!

Can you add this to [https://coderwall.com/p/t/ansible](https://coderwall.com/p/t/ansible) ?

---

<div class="post-metadata">

**Author:** ![Tin\_Tvrtkovic](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@Tin\_Tvrtkovic](https://forum.ansible.com/u/Tin_Tvrtkovic)\
**Post date:** [April 6, 2013, 12:29am UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/6 "2013-04-06T00:29:25Z")

</div>

Sure thing, I’ll get around to it tomorrow.

Cheers

---

<div class="post-metadata">

**Author:** ![Tin\_Tvrtkovic](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@Tin\_Tvrtkovic](https://forum.ansible.com/u/Tin_Tvrtkovic)\
**Post date:** [April 6, 2013, 6:46pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/7 "2013-04-06T18:46:54Z")

</div>

Here we go: [https://coderwall.com/p/bqgksg?i=16&p=2&q=sort%3Ascore+desc&t[]=ansible](https://coderwall.com/p/bqgksg?i=16&p=2&q=sort%3Ascore+desc&t%5B%5D=ansible)

I’m so bad at formatting.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 6, 2013, 8:06pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/8 "2013-04-06T20:06:19Z")

</div>

Indent each line by four characters for the markdown to kick in.

I agree it’s a little weird 🙂

---

<div class="post-metadata">

**Author:** ![Tin\_Tvrtkovic](https://avatars.discourse-cdn.com/v4/letter/t/bc8723/32.png) [@Tin\_Tvrtkovic](https://forum.ansible.com/u/Tin_Tvrtkovic)\
**Post date:** [April 6, 2013, 8:18pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/9 "2013-04-06T20:18:14Z")

</div>

That’s what I’m doing now. What’s funny is the preview looks fine, but the end result has wierd formatting. Meh,

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 6, 2013, 9:38pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/10 "2013-04-06T21:38:50Z")

</div>

I think it seems to want to wrap text too early in some cases.

I’m not sure why when we all have wide screen monitors coderwall wants to wrap things around 40 characters 🙂

---

<div class="post-metadata">

**Author:** ![Chris\_Bennett](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@Chris\_Bennett](https://forum.ansible.com/u/Chris_Bennett)\
**Post date:** [June 4, 2013, 1:36pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/11 "2013-06-04T13:36:22Z")

</div>

> This might not be helpful for you, but can you get an RPM for the repo? I  
> just do this:
> 
> &nbsp;&nbsp;- name: ensure PGDG Yum repo is installed
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: rpm -Uvh [http://yum.postgresql.org/9.2/redhat/rhel-6-x86\_64/pgdg-centos92-9.2-6.noarch.rpm](http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;creates=/etc/yum.repos.d/pgdg-92-centos.repo

This is exactly how I do it, but I'd still like to be able to disable  
the repo.

e.g. when I want repoforge added, I have a role:

repoforge/vars/main.yml:

---

<div class="post-metadata">

**Author:** ![Scott\_Sturdivant](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@Scott\_Sturdivant](https://forum.ansible.com/u/Scott_Sturdivant)\
**Post date:** [June 4, 2013, 2:47pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/12 "2013-06-04T14:47:40Z")

</div>

Haven’t used it myself, but have you looked at the [ini\_file](http://ansible.cc/docs/modules.html?highlight=replace#ini-file) module?

---

<div class="post-metadata">

**Author:** ![Chris\_Bennett](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@Chris\_Bennett](https://forum.ansible.com/u/Chris_Bennett)\
**Post date:** [June 5, 2013, 12:43am UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/13 "2013-06-05T00:43:09Z")

</div>

> Haven't used it myself, but have you looked at the  
> ini\_file\<[http://ansible.cc/docs/modules.html?highlight=replace#ini-file&gt;module](http://ansible.cc/docs/modules.html?highlight=replace#ini-file&gt;module)?

Hmm, no I didn't even think to consider it. But reading the doco, it  
may do exactly what I want. Thanks! 🙂

Chris

---

<div class="post-metadata">

**Author:** ![Matt\_Spaulding](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@Matt\_Spaulding](https://forum.ansible.com/u/Matt_Spaulding)\
**Post date:** [June 16, 2013, 5:56pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/14 "2013-06-16T17:56:59Z")

</div>

I just happen to have created a yum\_repository plugin [1] for Ansible based on my own needs. In the environment I work with we use a continuous integration system to generate new rpm repositories throughout the day, so it’s helpful to deal with them this way. It also greatly simplifies the code for making changes to existing repositories.

For instance, if I wanted to disable my Centos updates repository, I could use something like:

ansible all -m yum\_repository -a “id=updates state=disabled”

I haven’t submitted a pull request yet, but will if other people find it useful.

[1] [https://github.com/mspaulding06/ansible/blob/yum\_repository\_plugin/library/packaging/yum\_repository](https://github.com/mspaulding06/ansible/blob/yum_repository_plugin/library/packaging/yum_repository)

---

<div class="post-metadata">

**Author:** ![Johan\_Soderberg](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@Johan\_Soderberg](https://forum.ansible.com/u/Johan_Soderberg)\
**Post date:** [February 13, 2014, 1:22pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/15 "2014-02-13T13:22:54Z")

</div>

Hi,

The yum\_repository module sounds exactly what I’ve been looking for. Unfortunately the url doesn’t work and I’m unable to find it anywhere. Is it still available somewhere?

Thanks in advance,

/Johan

---

<div class="post-metadata">

**Author:** ![Cha\_Donghwi](https://avatars.discourse-cdn.com/v4/letter/c/858c86/32.png) [@Cha\_Donghwi](https://forum.ansible.com/u/Cha_Donghwi)\
**Post date:** [December 10, 2015, 2:04pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/16 "2015-12-10T14:04:20Z")

</div>

Is this still not implemented to ansible core?

2014년 2월 13일 목요일 오후 10시 22분 54초 UTC+9, Johan Söderberg 님의 말:

---

<div class="post-metadata">

**Author:** ![Dan\_Lang](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@Dan\_Lang](https://forum.ansible.com/u/Dan_Lang)\
**Post date:** [December 14, 2015, 7:03pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/17 "2015-12-14T19:03:20Z")

</div>

Check out the module index, there is [http://docs.ansible.com/ansible/yumrepo\_module.html](http://docs.ansible.com/ansible/yumrepo_module.html). This is an extras module.

---

<div class="post-metadata">

**Author:** ![Anthony\_Cheng](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@Anthony\_Cheng](https://forum.ansible.com/u/Anthony_Cheng)\
**Post date:** [May 10, 2016, 1:39pm UTC](https://forum.ansible.com/t/yum-repository-module-has-anyone-thought-of-doing-it/12630/18 "2016-05-10T13:39:04Z")

</div>

New link is here [http://docs.ansible.com/ansible/yum\_repository\_module.html](http://docs.ansible.com/ansible/yum_repository_module.html)
