{"id":1468,"date":"2024-06-23T13:48:58","date_gmt":"2024-06-23T13:48:58","guid":{"rendered":"http:\/\/shijuvarghese.com\/?p=1468"},"modified":"2025-05-23T18:46:31","modified_gmt":"2025-05-23T18:46:31","slug":"ansible-adding-a-yum-or-dnf-repository","status":"publish","type":"post","link":"http:\/\/shijuvarghese.com\/?p=1468","title":{"rendered":"Ansible: Adding a YUM or DNF repository"},"content":{"rendered":"<p>A <strong>yum<\/strong> or <strong>dnf<\/strong> repository can be added to managed nodes using Ansible. This is done using the ansible builtin yum_repository module.<\/p>\n<p>Basics of creating yum repositories can be found at this <a href=\"http:\/\/shijuvarghese.com\/?p=1460\" target=\"_blank\">link<\/a>.<\/p>\n<p>Below playbook adds a yum repository.<\/p>\n<p><strong>[root@centos9vm ~]#<\/strong> cat create_yum_repo.yml<\/p>\n<p>====== ==<br \/>\n&#8211; &#8211; &#8211;<br \/>\n<em>&#8211; name: Playbook to create a yum repository in manage nodes<\/em><br \/>\n<em>\u00a0 \u00a0hosts: 192.168.48.132<\/em><br \/>\n<em> \u00a0 \u00a0tasks:<\/em><br \/>\n<em> \u00a0 \u00a0\u00a0 \u00a0&#8211; name: Task to create yum repository<\/em><br \/>\n<em> \u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0ansible.builtin.yum_repository:<\/em><br \/>\n<em> \u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0file: fedora_example<\/em><br \/>\n<em> \u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0name: ExampleFedora<\/em><br \/>\n<em> \u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0baseurl: https:\/\/dl.fedoraproject.org\/pub\/epel\/9\/Everything\/x86_64\/<\/em><br \/>\n<em> \u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0gpgcheck: no<\/em><br \/>\n<em> \u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0enabled: yes<\/em><br \/>\n<em> \u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0description: fedora_example<\/em><\/p>\n<p>==== ==<\/p>\n<p>Let us check the managed node before running the playbook<\/p>\n<p><strong>[root@centos9test1 ~]#<\/strong> dnf repolist all | grep fedo<\/p>\n<p>The above command may not return any result<\/p>\n<p>Now let us run the playbook<\/p>\n<p><strong>[root@centos9vm ~]#<\/strong> ansible-navigator run -m stdout create_yum_repo.yml<\/p>\n<p>=== ==<\/p>\n<p><em>PLAY [Playbook to create a yum repository in manage nodes] *********************<\/em><\/p>\n<p><em>TASK [Gathering Facts] *********************************************************<\/em><br \/>\n<em>ok: [192.168.48.132]<\/em><\/p>\n<p><em>TASK [Task to create yum repository] *******************************************<\/em><br \/>\n<em>changed: [192.168.48.132]<\/em><\/p>\n<p><em>PLAY RECAP *********************************************************************<\/em><br \/>\n<em>192.168.48.132 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0<\/em><\/p>\n<p>==== ===<\/p>\n<p>Let us recheck now<\/p>\n<p><strong>[root@centos9test1 ~]#<\/strong> dnf repolist all | grep fedo<br \/>\n<em>ExampleFedora fedora_example enabled<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>A yum or dnf repository can be added to managed nodes using Ansible. This is done using the ansible builtin yum_repository module. Basics of creating <a class=\"mh-excerpt-more\" href=\"http:\/\/shijuvarghese.com\/?p=1468\" title=\"Ansible: Adding a YUM or DNF repository\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":1792,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,21,4],"tags":[],"class_list":["post-1468","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ansible","category-devops","category-installation"],"_links":{"self":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/1468","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1468"}],"version-history":[{"count":6,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/1468\/revisions"}],"predecessor-version":[{"id":1510,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/1468\/revisions\/1510"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/media\/1792"}],"wp:attachment":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1468"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}