Local repo in CentOs7 using Ansible

1,275 views
Skip to first unread message

Hariprasad S

unread,
Jul 14, 2016, 12:50:56 PM7/14/16
to Ansible Project
Hi All, 
I'm pretty new to Ansible. Have started working on Ansible about a week back.
I have given a task to create a local repo using ansible in CentOs system.

This is my yaml file:
---

- name: configuring yum local repository
  hosts: testServer
  remote_user: root
  become: yes

  tasks:
  - name: Add repository
    yum_repository:
      name: custom_repository
      description: local_repository
      baseurl: file:///root/
      enabled: yes

The .repo file is create /etc/yum.repos.d/ ,but i couldn't able to install any package using this repo. When i tried to install rpm which is place in /root/, it give the following error:

Setting up Install Process
Loading mirror speeds from cached hostfile
file:///root/repodata/repomd.xml: [Errno 14] Could not open/read file:///root/repodata/repomd.xml
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: custom_repository. Please verify its path and try again

I understand this repomd.xml can be created by using manually by executing "createrepo /root/" executable which come as part of yum commands. I want to know, how the "createrepo command" can be executed using ansible scripts? what is parameter i have to set in Ansible script to create the repomd.xml ?

Kindly help.


Thanks
Hari

Dick Davies

unread,
Jul 14, 2016, 3:31:57 PM7/14/16
to ansible list
Hi

you want to use a "command:" task.

If I was you I'd

* create a handler to run the createrepo command
* have a list of files you want to fill that directory
* upload the files with Ansible e.g. with a copy: task into the directory
* have a notify: clause on the file upload task (see docs) that
triggers the createrepo handler when the upload task changes
* oh, and use a different directory from /root ...

Have fun!
> --
> 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.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/41f8519a-e693-4187-a541-99d4834565ed%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages