# My Ansible roles for Rocky Linux

**URL:** <https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250>\
**Category:** Rocky Linux Help & Support\
**Created:** [April 25, 2025, 8:16am UTC](https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250 "2025-04-25T08:16:00Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![microlinux](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/microlinux/32/1244_2.png) [@microlinux](https://forums.rockylinux.org/u/microlinux)\
**Post date:** [April 25, 2025, 8:16am UTC](https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250/1 "2025-04-25T08:16:00Z")

</div>

Hi,

I’ve started to publish a handful of Ansible roles for Rocky Linux on GitLab. Here for example:

- [Nicolas Kovacs / Ansible role rockylinux9\_repos\_official · GitLab](https://gitlab.com/kikinovak/rockylinux9_repos_official)

- [Nicolas Kovacs / Ansible role rockylinux9\_repos\_epel · GitLab](https://gitlab.com/kikinovak/rockylinux9_repos_epel)

- [Nicolas Kovacs / Ansible role rockylinux9\_repos\_rpmfusion · GitLab](https://gitlab.com/kikinovak/rockylinux9_repos_rpmfusion)

- [Nicolas Kovacs / Ansible role rockylinux9\_install\_kdebase · GitLab](https://gitlab.com/kikinovak/rockylinux9_install_kdebase)

- [Nicolas Kovacs / Ansible role rockylinux9\_install\_gdm · GitLab](https://gitlab.com/kikinovak/rockylinux9_install_gdm)

I’m relatively new to this. Before going any further and writing more roles in the days and weeks (and months) to come, I thought I’d ask. Does this seem to fit the current standards? Do you have any suggestions in regard to best practices? Did I miss something?

So far this works OK. I can import the roles in my playbooks using a `requirements.yml` file, so stuff is much more modular and reusable.

Any suggestions ?

Niki

---

<div class="post-metadata">

**Author:** ![jlehtone](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jlehtone](https://forums.rockylinux.org/u/jlehtone)\
**Post date:** [April 25, 2025, 11:00am UTC](https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250/2 "2025-04-25T11:00:00Z")

</div>

Nice.

* * *

You do remove some \*.repo files that are from packages? Package update would re-install them.  
Then again, edit of those files (to wipe them empty, for example) will make the potential update add equivalent \*.rpmnew files.

The lists of “nearby mirrors” could be in vars. Easier for other sites to override.

---

<div class="post-metadata">

**Author:** ![microlinux](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/microlinux/32/1244_2.png) [@microlinux](https://forums.rockylinux.org/u/microlinux)\
**Post date:** [April 25, 2025, 4:59pm UTC](https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250/3 "2025-04-25T16:59:03Z")

</div>

OK noted.

Besides that, stuff in `README.md` and in `meta/main.yml` seems OK ?

---

<div class="post-metadata">

**Author:** ![iwalker](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/iwalker/32/2599_2.png) [@iwalker](https://forums.rockylinux.org/u/iwalker)\
**Post date:** [April 25, 2025, 6:22pm UTC](https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250/4 "2025-04-25T18:22:39Z")

</div>

I think the `main.yml` are fine. The only thing I would question are the dependencies. I’m pretty sure rpmfusion can be used without epel as a dependency. But assuming that your playbook for rpmfusion is dependent on something from both of these repositories, then that would probably explain it. However, I don’t see anything in the `tasks.yml` that would hint at it requiring epel as a dependency. Again with KDE, rpmfusion is mentioned as a dependency, but is it really a dependency in that the KDE tasks installs something from rpmfusion? I’m pretty sure KDE is just pulling mostly from EPEL with some distro packages from baseos or appstream. And GDM is in the distro anyway, so prob doesn’t need to be dependent on KDE.

---

<div class="post-metadata">

**Author:** ![iwalker](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/iwalker/32/2599_2.png) [@iwalker](https://forums.rockylinux.org/u/iwalker)\
**Post date:** [April 25, 2025, 6:35pm UTC](https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250/5 "2025-04-25T18:35:02Z")

</div>

One other note, is that with your tasks, you don’t need to put them in a file called `main.yml`, but what you can do is separate them out and make things more logical and easier to read. Here’s an example of something I did once for an app:

```auto
.
├── ansible.cfg
├── app.yml
├── files
│ └── apt
│ ├── app.list
│ ├── mssql-server.list
│ ├── mssql-tools.list
│ └── sources.list
├── inventory
├── README.md
├── tasks
│ ├── add_repos.yml
│ ├── clone_scripts.yml
│ ├── configure_cron.yml
│ ├── configure_timezone.yml
│ ├── enable_firewalld.yml
│ ├── install_deps.yml
│ ├── restart_services.yml
│ └── set_php_parms.yml
├── templates
│ └── cron_onsite.j2
└── vars
    ├── debian.yml
    ├── rhel.yml
    └── ubuntu.yml

```

so you can see my structure slightly different. Various task files for doing things like configuring and enabling firewall for example. The variables I separated out from the main play `app.yml` and depending on what distro I’m deploying the app, be it Debian, Red Hat or Ubuntu it gets configured with the specific set of variables.

Obviously for quick and simple plays, there’s no need to go crazy 🙂

---

<div class="post-metadata">

**Author:** ![microlinux](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/microlinux/32/1244_2.png) [@microlinux](https://forums.rockylinux.org/u/microlinux)\
**Post date:** [April 25, 2025, 7:11pm UTC](https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250/6 "2025-04-25T19:11:29Z")

</div>

> [@iwalker](#):
>
> I think the `main.yml` are fine. The only thing I would question are the dependencies. I’m pretty sure rpmfusion can be used without epel as a dependency. But assuming that your playbook for rpmfusion is dependent on something from both of these repositories, then that would probably explain it. However, I don’t see anything in the `tasks.yml` that would hint at it requiring epel as a dependency. Again with KDE, rpmfusion is mentioned as a dependency, but is it really a dependency in that the KDE tasks installs something from rpmfusion? I’m pretty sure KDE is just pulling mostly from EPEL with some distro packages from baseos or appstream. And GDM is in the distro anyway, so prob doesn’t need to be dependent on KDE.

There’s a reason for all these tweaks. This is my personal blend of KDE with quite a few customizations. KDE relies on ffmpeg, and I’m pulling in the more functional package from RPMFusion so things like thumbnails work for all video formats. SDDM doesn’t play well with NVidia drivers so I’m replacing it with my tweaked version of GDM (hence the dependency).

---

<div class="post-metadata">

**Author:** ![microlinux](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/microlinux/32/1244_2.png) [@microlinux](https://forums.rockylinux.org/u/microlinux)\
**Post date:** [April 25, 2025, 7:13pm UTC](https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250/7 "2025-04-25T19:13:23Z")

</div>

I know the method you use. Unfortunately you can’t really manage handlers with it. I have quite a few in my 200+ tasks playbook. As far as I’m concerned, roles are the way to go. (Waiting for `jlehtone` to chime in here.)

---

<div class="post-metadata">

**Author:** ![iwalker](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/iwalker/32/2599_2.png) [@iwalker](https://forums.rockylinux.org/u/iwalker)\
**Post date:** [April 25, 2025, 7:25pm UTC](https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250/8 "2025-04-25T19:25:54Z")

</div>

> [@microlinux](#):
>
> There’s a reason for all these tweaks. This is my personal blend of KDE with quite a few customizations. KDE relies on ffmpeg, and I’m pulling in the more functional package from RPMFusion so things like thumbnails work for all video formats. SDDM doesn’t play well with NVidia drivers so I’m replacing it with my tweaked version of GDM (hence the dependency).

OK understood, just thought I’d mention it 🙂

---

<div class="post-metadata">

**Author:** ![iwalker](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/iwalker/32/2599_2.png) [@iwalker](https://forums.rockylinux.org/u/iwalker)\
**Post date:** [April 25, 2025, 7:27pm UTC](https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250/9 "2025-04-25T19:27:38Z")

</div>

> [@microlinux](#):
>
> I know the method you use. Unfortunately you can’t really manage handlers with it. I have quite a few in my 200+ tasks playbook. As far as I’m concerned, roles are the way to go. (Waiting for `jlehtone` to chime in here.)

I do have handlers in mine, they work fine with the way I’ve done it. The one I have mentioned showing the directory structure is a role, but with a load of features that it’s dealing with. Roles can be simple one-off things, but they can also be complex.

Mine does lack some of those default and main directories, but that’s just the way I’ve done it because I’m not publishing it anywhere.

---

<div class="post-metadata">

**Author:** ![jlehtone](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jlehtone](https://forums.rockylinux.org/u/jlehtone)\
**Post date:** [April 26, 2025, 5:18pm UTC](https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250/10 "2025-04-26T17:18:06Z")

</div>

Roles can indeed be complex and when a play does `include_role` it can name task-file. The System Roles (in `rhel-system-roles`) are clearly not simple.

* * *

> [@iwalker](#):
>
> ```auto
> └── vars
> ├── debian.yml
> ├── rhel.yml
> └── ubuntu.yml
> 
> ```

This reveals another aspect. You have written the role for three different distros and its tasks probably include role-vars based on where the role is used.

* * *

The `ansible-galaxy role init` creates a skeleton for role – empty ‘main.yml’ in every directory.

---

<div class="post-metadata">

**Author:** ![iwalker](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/iwalker/32/2599_2.png) [@iwalker](https://forums.rockylinux.org/u/iwalker)\
**Post date:** [April 26, 2025, 5:38pm UTC](https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250/11 "2025-04-26T17:38:37Z")

</div>

> [@jlehtone](#):
>
> This reveals another aspect. You have written the role for three different distros and its tasks probably include role-vars based on where the role is used.

Correct, a combination of `when:` fields with ansible\_distribution, as well as going further with `ansible_distribution_major_version` depending on EL7 or EL8 for example.

> [@jlehtone](#):
>
> The `ansible-galaxy role init` creates a skeleton for role – empty ‘main.yml’ in every directory.

Yup, true, I just got rid of those parts that I didn’t need, as mentioned, I’m not publishing it anywhere, so it was superfluous to my needs. But I do have roles where I have left these because I distribute them.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/rockylinux/original/1X/91b7219eec10e30013422e4df76c1d898711a5d5.svg) [@system](https://forums.rockylinux.org/u/system)\
**Post date:** [June 25, 2025, 5:39pm UTC](https://forums.rockylinux.org/t/my-ansible-roles-for-rocky-linux/18250/12 "2025-06-25T17:39:23Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
