tyla@fedora:~/code/rpm$ tar czf ~/rpmbuild/SOURCES/ansible-role-myrole.tar.gz myrole/
tyla@fedora:~/code/rpm$ vi ~/rpmbuild/SPECS/ansible-role-myrole.spec
Name: ansible-role-myrole
Version: 1.0.0
Release: 1%{?dist}
Summary: Ansible role for <describe your role>
License: MIT
Source0: %{name}.tar.gz
BuildArch: noarch
Requires: ansible
%description
This is an Ansible role for <describe your role here>.
%prep
%setup -q -n myrole
%build
# No build steps needed
%install
mkdir -p %{buildroot}/usr/share/ansible/roles
cp -a . %{buildroot}/usr/share/ansible/roles/myrole
%files
/usr/share/ansible/roles/myrole
%changelog
* Tue Oct 29 2024 Your Name <[email protected]> - 1.0.0-1
- Initial RPM release
tyla@fedora:~$ cd /opt
tyla@fedora:/opt$ sudo mkdir myrepo
tyla@fedora:/opt$ ll
total 0
drwxr-xr-x. 2 root root 6 Nov 13 11:59 myrepo
tyla@fedora:/opt$ sudo chown -R tyla:tyla myrepo
tyla@fedora:/opt$ cp ~/rpmbuild/RPMS/noarch/* myrepo/
tyla@fedora:/opt$ tree myrepo/
myrepo/
├── ansible-role-merole-1.0.0-1.fc41.noarch.rpm
└── ansible-role-myrole-1.0.0-1.fc41.noarch.rpm
1 directory, 2 files
tyla@fedora:/opt$ ll myrepo/
total 24
-rw-r--r--. 1 tyla tyla 10253 Nov 13 12:00 ansible-role-merole-1.0.0-1.fc41.noarch.rpm
-rw-r--r--. 1 tyla tyla 10254 Nov 13 12:00 ansible-role-myrole-1.0.0-1.fc41.noarch.rpm
tyla@fedora:/opt$ createrepo myrepo/
Directory walk started
Directory walk done - 2 packages
Temporary output repo path: myrepo/.repodata/
Pool started (with 5 workers)
Pool finished
tyla@fedora:/opt$ cd myrepo/
tyla@fedora:/opt/myrepo$ ll
total 28
-rw-r--r--. 1 tyla tyla 10253 Nov 13 12:00 ansible-role-merole-1.0.0-1.fc41.noarch.rpm
-rw-r--r--. 1 tyla tyla 10254 Nov 13 12:00 ansible-role-myrole-1.0.0-1.fc41.noarch.rpm
drwxr-xr-x. 2 tyla tyla 4096 Nov 13 12:01 repodata
tyla@fedora:~$ sudo vi /etc/yum.repos.d/myrepo.repo
[myrepo]
name=My Custom Repository
baseurl=file:///opt/myrepo # For a local repository
# or use a network path, such as:
# baseurl=http://192.168.1.10/myrepo
enabled=1
gpgcheck=0
# update the dnf repository cache
tyla@fedora:~$ sudo dnf update -y
Updating and loading repositories:
My Custom Repository 100% | 28.0 KiB/s | 2.2 KiB | 00m00s
Repositories loaded.
Nothing to do.
# install the custom Ansible role
tyla@fedora:~$ sudo dnf install ansible-role-myrole
Updating and loading repositories:
Repositories loaded.
Package Arch Version Repository Size
Installing:
ansible-role-myrole noarch 1.0.0-1.fc41 myrepo 3.1 KiB
Transaction Summary:
Installing: 1 package
Total size of inbound packages is 10 KiB. Need to download 10 KiB.
After this operation, 3 KiB extra will be used (install 3 KiB, remove 0 B).
Is this ok [y/N]: y
[1/1] ansible-role-myrole-0:1.0.0-1.fc41.noarch 100% | 38.8 KiB/s | 10.0 KiB | 00m00s
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[1/1] Total 100% | 38.7 KiB/s | 10.0 KiB | 00m00s
Running transaction
[1/3] Verify package files 100% | 333.0 B/s | 1.0 B | 00m00s
[2/3] Prepare transaction 100% | 11.0 B/s | 1.0 B | 00m00s
[3/3] Installing ansible-role-myrole-0:1.0.0-1.fc41.noarch 100% | 8.8 KiB/s | 5.8 KiB | 00m01s
Warning: skipped PGP checks for 1 package from repository: myrepo
Complete!
# verify its installation
tyla@fedora:~$ cd /usr/share/ansible/roles
tyla@fedora:/usr/share/ansible/roles$ tree
.
└── myrole
├── defaults
│ └── main.yml
├── files
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── README.md
├── tasks
│ └── main.yml
├── templates
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.yml
10 directories, 8 files
# attempt to install the same rpm package to see what happens
tyla@fedora:/usr/share/ansible/roles$ cd
tyla@fedora:~$ sudo dnf install ansible-role-myrole
Updating and loading repositories:
Repositories loaded.
Package "ansible-role-myrole-1.0.0-1.fc41.noarch" is already installed.
Nothing to do.
# uninstall the rpm package
tyla@fedora:~$ sudo dnf remove ansible-role-myrole
Package Arch Version Repository Size
Removing:
ansible-role-myrole noarch 1.0.0-1.fc41 myrepo 3.1 KiB
Transaction Summary:
Removing: 1 package
Is this ok [y/N]: y
Running transaction
[1/2] Prepare transaction 100% | 10.0 B/s | 1.0 B | 00m00s
[2/2] Erasing ansible-role-myrole-0:1.0.0-1.fc41.noarch 100% | 21.0 B/s | 17.0 B | 00m01s
Complete!
# verify the uninstallation
tyla@fedora:~$ cd /usr/share/ansible/roles/
tyla@fedora:/usr/share/ansible/roles$ ll
total 0
# now reinstall both myrole and merole
tyla@fedora:/usr/share/ansible/roles$ sudo dnf install ansible-role-myrole ansible-role-merole -y
Updating and loading repositories:
Repositories loaded.
Package Arch Version Repository Size
Installing:
ansible-role-merole noarch 1.0.0-1.fc41 myrepo 3.1 KiB
ansible-role-myrole noarch 1.0.0-1.fc41 myrepo 3.1 KiB
Transaction Summary:
Installing: 2 packages
Total size of inbound packages is 20 KiB. Need to download 20 KiB.
After this operation, 6 KiB extra will be used (install 6 KiB, remove 0 B).
[1/2] ansible-role-myrole-0:1.0.0-1.fc41.noarch 100% | 500.7 KiB/s | 10.0 KiB | 00m00s
[2/2] ansible-role-merole-0:1.0.0-1.fc41.noarch 100% | 270.6 KiB/s | 10.0 KiB | 00m00s
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[2/2] Total 100% | 527.0 KiB/s | 20.0 KiB | 00m00s
Running transaction
[1/4] Verify package files 100% | 666.0 B/s | 2.0 B | 00m00s
[2/4] Prepare transaction 100% | 21.0 B/s | 2.0 B | 00m00s
[3/4] Installing ansible-role-merole-0:1.0.0-1.fc41.noarch 100% | 70.6 KiB/s | 5.8 KiB | 00m00s
[4/4] Installing ansible-role-myrole-0:1.0.0-1.fc41.noarch 100% | 5.3 KiB/s | 5.8 KiB | 00m01s
Warning: skipped PGP checks for 2 packages from repository: myrepo
Complete!
# verify the installation
tyla@fedora:/usr/share/ansible/roles$ tree
.
├── merole
│ ├── defaults
│ │ └── main.yml
│ ├── files
│ ├── handlers
│ │ └── main.yml
│ ├── meta
│ │ └── main.yml
│ ├── README.md
│ ├── tasks
│ │ └── main.yml
│ ├── templates
│ ├── tests
│ │ ├── inventory
│ │ └── test.yml
│ └── vars
│ └── main.yml
└── myrole
├── defaults
│ └── main.yml
├── files
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── README.md
├── tasks
│ └── main.yml
├── templates
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.yml
19 directories, 16 files
tyla@fedora:~$ createrepo --update /opt/myrepo
Directory walk started
Directory walk done - 2 packages
Loaded information about 2 packages
Temporary output repo path: /opt/myrepo/.repodata/
Pool started (with 5 workers)
Pool finished
New and old repodata match, not updating.
tyla@fedora:~$ cd /opt/myrepo/
tyla@fedora:/opt/myrepo$ rm -f ansible-role-merole-1.0.0-1.fc41.noarch.rpm
tyla@fedora:/opt/myrepo$ ll
total 16
-rw-r--r--. 1 tyla tyla 10254 Nov 13 12:00 ansible-role-myrole-1.0.0-1.fc41.noarch.rpm
drwxr-xr-x. 2 tyla tyla 4096 Nov 13 12:01 repodata
tyla@fedora:/opt/myrepo$ cd
tyla@fedora:~$ createrepo --update /opt/myrepo
Directory walk started
Directory walk done - 1 packages
Loaded information about 1 packages
Temporary output repo path: /opt/myrepo/.repodata/
Pool started (with 5 workers)
Pool finished
# prepare the required directories and copy Ansible role files and directories
tyla@ubuntu:~/code/deb$ mkdir -p ~/ansible-role-myrole/usr/share/ansible/roles/myrole
tyla@ubuntu:~/code/deb$ cp -r myrole/* ~/ansible-role-myrole/usr/share/ansible/roles/myrole/
tyla@ubuntu:~/code/deb$ mkdir ~/ansible-role-myrole/DEBIAN
# prepare the control file
tyla@ubuntu:~/code/deb$ vi ~/ansible-role-myrole/DEBIAN/control
Package: ansible-role-myrole
Version: 1.0.0
Section: misc
Priority: optional
Architecture: all
Depends: ansible
Maintainer: Your Name <[email protected]>
Description: Ansible role for <describe your role here>
# set permission for these two directories
tyla@ubuntu:~/code/deb$ chmod -R 755 ~/ansible-role-myrole/
tyla@ubuntu:~/code/deb$ chmod -R 755 ~/ansible-role-myrole/DEBIAN/
tyla@ubuntu:~/code/deb$ cd
tyla@ubuntu:~$ dpkg-deb --build ansible-role-myrole
dpkg-deb: building package 'ansible-role-myrole' in 'ansible-role-myrole.deb'.
tyla@ubuntu:~$ sudo mkdir -p /opt/myrepo/pool
tyla@ubuntu:~$ cd /opt
tyla@ubuntu:/opt$ sudo chown -R tyla:tyla myrepo/
tyla@ubuntu:/opt$ cd
tyla@ubuntu:~$ cp *.deb /opt/myrepo/pool/
tyla@ubuntu:~$ cd /opt/myrepo/pool/
tyla@ubuntu:/opt/myrepo/pool$ ll
total 16
drwxr-xr-x 2 tyla tyla 4096 Nov 13 09:30 ./
drwxr-xr-x 3 tyla tyla 4096 Nov 13 09:29 ../
-rw-r--r-- 1 tyla tyla 2230 Nov 13 09:30 ansible-role-merole.deb
-rw-r--r-- 1 tyla tyla 2238 Nov 13 09:30 ansible-role-myrole.deb
tyla@ubuntu:/opt/myrepo/pool$ cd ..
tyla@ubuntu:/opt/myrepo$ dpkg-scanpackages pool /dev/null | gzip -9c > Packages.gz
dpkg-scanpackages: warning: Packages in archive but missing from override file:
dpkg-scanpackages: warning: ansible-role-merole ansible-role-myrole
dpkg-scanpackages: info: Wrote 2 entries to output Packages file.
tyla@ubuntu:/opt/myrepo$ tree
.
├── Packages.gz
└── pool
├── ansible-role-merole.deb
└── ansible-role-myrole.deb
# install ansible-role-myrole deb package
tyla@ubuntu:/opt/myrepo$ sudo apt install ansible-role-myrole
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
ansible-role-myrole
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/2,238 B of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 file:/opt/myrepo ./ ansible-role-myrole 1.0.0 [2,238 B]
Selecting previously unselected package ansible-role-myrole.
(Reading database ... 119045 files and directories currently installed.)
Preparing to unpack .../pool/ansible-role-myrole.deb ...
Unpacking ansible-role-myrole (1.0.0) ...
Setting up ansible-role-myrole (1.0.0) ...
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.
# verify the installation
tyla@ubuntu:/opt/myrepo$ cd /usr/share/ansible/roles/
tyla@ubuntu:/usr/share/ansible/roles$ tree
.
└── myrole
├── defaults
│ └── main.yml
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── README.md
├── tasks
│ └── main.yml
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.yml
7 directories, 8 files
# uninstall ansible-role-myrole
tyla@ubuntu:/usr/share/ansible/roles$ sudo apt remove ansible-role-myrole
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
ansible-role-myrole
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 119062 files and directories currently installed.)
Removing ansible-role-myrole (1.0.0) ...
sh: 0: getcwd() failed: No such file or directory
# verify the uninstallation
tyla@ubuntu:/usr/share/ansible/roles$ tree
.
0 directories, 0 files