yum_repository module (has anyone thought of doing it...)

4,487 views
Skip to first unread message

Jimmy Tang

unread,
Apr 5, 2013, 4:18:37 AM4/5/13
to ansible...@googlegroups.com
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/ 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.

seth vidal

unread,
Apr 5, 2013, 9:48:03 AM4/5/13
to ansible...@googlegroups.com, jcf...@gmail.com
But a yum repository is just a simple file. Why not just use copy or
template or even get_url?

-sv

Michael DeHaan

unread,
Apr 5, 2013, 11:50:24 AM4/5/13
to ansible...@googlegroups.com, jcf...@gmail.com
I concur, I would almost always just template these into yum.repos.d





--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.





--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Tin Tvrtković

unread,
Apr 5, 2013, 6:04:24 PM4/5/13
to ansible...@googlegroups.com
This might not be helpful for you, but can you get an RPM for the repo? I just do this:

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

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

Michael DeHaan

unread,
Apr 5, 2013, 8:11:09 PM4/5/13
to ansible...@googlegroups.com
not a bad trick! 

Can you add this to https://coderwall.com/p/t/ansible ?




--

Tin Tvrtković

unread,
Apr 5, 2013, 8:29:25 PM4/5/13
to ansible...@googlegroups.com
Sure thing, I'll get around to it tomorrow.

Cheers

Tin Tvrtković

unread,
Apr 6, 2013, 2:46:54 PM4/6/13
to ansible...@googlegroups.com
Here we go: https://coderwall.com/p/bqgksg?i=16&p=2&q=sort%3Ascore+desc&t%5B%5D=ansible

I'm so bad at formatting.


On Saturday, April 6, 2013 2:11:09 AM UTC+2, Michael DeHaan wrote:

Michael DeHaan

unread,
Apr 6, 2013, 4:06:19 PM4/6/13
to ansible...@googlegroups.com
Indent each line by four characters for the markdown to kick in.

I agree it's a little weird :)


Tin Tvrtković

unread,
Apr 6, 2013, 4:18:14 PM4/6/13
to ansible...@googlegroups.com
That's what I'm doing now. What's funny is the preview looks fine, but the end result has wierd formatting. Meh,

Michael DeHaan

unread,
Apr 6, 2013, 5:38:50 PM4/6/13
to ansible...@googlegroups.com
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 :)


Chris Bennett

unread,
Jun 4, 2013, 9:36:22 AM6/4/13
to ansible...@googlegroups.com
> This might not be helpful for you, but can you get an RPM for the repo? I
> just do this:
>
> - name: ensure PGDG Yum repo is installed
>
> shell: rpm -Uvh http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm
> 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:
---
rpmforge_rpm_name: rpmforge-release-0.5.3-1.el6.rf.{{ ansible_machine }}.rpm

$ ls repoforge/files/ | cat
rpmforge-release-0.5.3-1.el6.rf.i686.rpm
rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

tasks/main.yml:
- copy: src={{rpmforge_rpm_name}}
dest=/usr/local/src/{{rpmforge_rpm_name}}
- shell: rpm -ivh /usr/local/src/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
creates=/etc/yum.repos.d/rpmforge.repo
- shell: rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag && touch /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag.imported
creates=/etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag.imported

The yum.repos.d file has 3 repos, 1 enabled & two disabled:

# egrep '(^\[|enabled =)' rpmforge.repo
[rpmforge]
enabled = 1
[rpmforge-extras]
enabled = 0
[rpmforge-testing]
enabled = 0

Having a yum_repository module would allow the managing of specific repo
parameters like enabled, includepkgs, without templating the parts that might
change due to a 'xx-release' repo rpm, like the baseurl or mirrorlist url.

Currently, to achieve all repos disabled, I do the nasty:

# determine if repo is enabled and then disable if necessary
- shell: grep -q 'enabled = 1' /etc/yum.repos.d/rpmforge.repo
register: yum_repo_rpmforge_enabled
ignore_errors: yes
- shell: sed -i -e 's/enabled = 1/enabled = 0/g' /etc/yum.repos.d/rpmforge.repo
only_if: "${yum_repo_rpmforge_enabled.rc} == 0"

I couldn't get lineinfile to do what I want when multiple lines matching the
regex need to be changed. Any tips?

Thanks,

Chris

Scott Sturdivant

unread,
Jun 4, 2013, 10:47:40 AM6/4/13
to ansible...@googlegroups.com
Haven't used it myself, but have you looked at the ini_file module? 


Chris Bennett

unread,
Jun 4, 2013, 8:43:09 PM6/4/13
to ansible...@googlegroups.com
> Haven't used it myself, but have you looked at the
> ini_file<http://ansible.cc/docs/modules.html?highlight=replace#ini-file>module?

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

Chris

Matt Spaulding

unread,
Jun 16, 2013, 1:56:59 PM6/16/13
to ansible...@googlegroups.com
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.

Johan Söderberg

unread,
Feb 13, 2014, 8:22:54 AM2/13/14
to ansible...@googlegroups.com
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

Cha Donghwi

unread,
Dec 10, 2015, 9:23:27 AM12/10/15
to Ansible Project
Is this still not implemented to ansible core? 



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

Dan Lang

unread,
Dec 14, 2015, 2:03:20 PM12/14/15
to Ansible Project
Check out the module index, there is http://docs.ansible.com/ansible/yumrepo_module.html. This is an extras module. 

Anthony Cheng

unread,
May 10, 2016, 9:39:04 AM5/10/16
to Ansible Project
Reply all
Reply to author
Forward
0 new messages