Download playbook at my github: https://github.com/vominhtri1991/playbook_create_localrepos.git
1/Prepare inventory file for managed server:
2/Main sections of playbook:
- Create variable for storing OS distribution support (this playbook run on only server using RedHat, Centos or Fedora), variable store source path on managed server using for create local repository and variable description of new repository
- name: Create Local Repository On Redhat/Centos Server
hosts: webserver
become: true
vars:
support_os:
- RedHat
- Centos
- Fedora
source_repos: "/local_repos"
repos_description: "New Local Repos"
- Create task for running command to checking source path existing on managed server and register output of command to variable
tasks:
- name: Checking source path of local repo existing
shell: "ls -ld {{ source_repos }}"
ignore_errors: true
register: output_check
- All task for creating new local repository will grouping with block section and using same condition checking os supported and result of command checking source path task
- name: Create Local Repository If Existing Source And OS Support
block:
- name: Install createrepe package
yum:
name: createrepo
state: present
- name: Create And Update Repo From source
shell: "createrepo {{ source_repos }};createrepo --update {{ source_repos }}"
- name: Configure Local reposfor client
copy:
dest: /etc/yum.repos.d/new_local.repo
content: |
[mylocalrepo]
name="{{ repos_description }}"
baseurl = file://{{ source_repos }}
gpgcheck=0
- name: Enable new repository for yum module
shell: "yum --enablerepo=mylocalrepo"
ignore_errors: true
when:
- ansible_distribution in support_os
- output_check.rc == 0
3/Running playbook and checking new repo created on managed server: