Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/update-roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ jobs:
branch: automation/update-ansible-roles
delete-branch: true
base: master
add-paths: _data/ansible_roles.yml
add-paths: |
_data/ansible_roles.yml
_data/ansible_role_repositories.yml
commit-message: Update Ansible role list
title: Update Ansible role list
body: |
Refresh `_data/ansible_roles.yml` from public `buluma/ansible-role-*` repositories.
Archived repositories are excluded.
Refresh the Ansible Galaxy role index and GitHub repository slug mapping from public `buluma/ansible-role-*` repositories.
Galaxy role names use underscores, and archived repositories are excluded.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ python scripts/update_roles.py list
python scripts/update_roles.py sync
```

This syncs public `buluma/ansible-role-*` repositories into the role list and
skips archived repositories. The **Update Ansible roles** workflow runs daily
or can be started manually from the Actions tab; it opens or updates a PR for
the generated change.
This syncs public `buluma/ansible-role-*` repositories into the role list,
converts dashes in repository names to Galaxy-compatible underscores, and skips
archived repositories. The **Update Ansible roles** workflow runs daily or can
be started manually from the Actions tab; it opens or updates a PR for the
generated role list and repository slug mapping.

The workflow needs a repository secret named `ROLE_SYNC_TOKEN`: a fine-grained
token with **Contents: read and write** and **Pull requests: read and write**
Expand Down
1 change: 1 addition & 0 deletions _data/ansible_role_repositories.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
7 changes: 3 additions & 4 deletions _data/ansible_roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
- debug
- demo
- dhcpd
- digitalocean-agent
- digitalocean_agent
- diskspace
- dns
- dnsmasq
Expand Down Expand Up @@ -115,7 +115,7 @@
- kibana
- kubectl
- kubernetes
- lemp-stack
- lemp_stack
- libvirt
- local
- locale
Expand All @@ -139,7 +139,7 @@
- multi
- mysql
- netdata
- netiq-sentinel-syslog-event-source
- netiq_sentinel_syslog_event_source
- nfs
- nginx
- nodejs
Expand Down Expand Up @@ -173,7 +173,6 @@
- rclone
- reboot
- redis
- redmine-1
- remi
- repo_epel
- restore
Expand Down
2 changes: 1 addition & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ understand what distributions and their versions are tested, have a look at the

| Role | Galaxy | CI Status | Version | Downloads |
|------|--------|-----------|---------|-----------|
{% for role in roles %}| [`{{ role }}`](https://galaxy.ansible.com/buluma/{{ role }}) | [![Galaxy](https://img.shields.io/badge/galaxy-{{ role }}-brightgreen?logo=ansible)](https://galaxy.ansible.com/buluma/{{ role }}) | [![CI](https://github.com/buluma/ansible-role-{{ role }}/actions/workflows/molecule.yml/badge.svg)](https://github.com/buluma/ansible-role-{{ role }}/actions/workflows/molecule.yml) | [![Version](https://img.shields.io/github/commits-since/buluma/ansible-role-{{ role }}/latest.svg)](https://github.com/buluma/ansible-role-{{ role }}/releases) | [![Downloads](https://img.shields.io/ansible/role/d/buluma/{{ role }})](https://galaxy.ansible.com/buluma/{{ role }}) |
{% for role in roles %}{% assign repository = site.data.ansible_role_repositories[role] | default: role %}| [`{{ role }}`](https://galaxy.ansible.com/buluma/{{ role }}) | [![Galaxy](https://img.shields.io/badge/galaxy-{{ role }}-brightgreen?logo=ansible)](https://galaxy.ansible.com/buluma/{{ role }}) | [![CI](https://github.com/buluma/ansible-role-{{ repository }}/actions/workflows/molecule.yml/badge.svg)](https://github.com/buluma/ansible-role-{{ repository }}/actions/workflows/molecule.yml) | [![Version](https://img.shields.io/github/commits-since/buluma/ansible-role-{{ repository }}/latest.svg)](https://github.com/buluma/ansible-role-{{ repository }}/releases) | [![Downloads](https://img.shields.io/ansible/role/d/buluma/{{ role }})](https://galaxy.ansible.com/buluma/{{ role }}) |
{% endfor %}
19 changes: 14 additions & 5 deletions scripts/update_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
import yaml

ROLES_FILE = "_data/ansible_roles.yml"
ROLE_REPOSITORIES_FILE = "_data/ansible_role_repositories.yml"
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
GITHUB_OWNER = "buluma"
ROLE_REPOSITORY_PREFIX = "ansible-role-"
ROLE_NAME_OVERRIDES = {
"digitalocean_agent": "digitalocean-agent",
"netiq_sentinel_syslog_event_source": "netiq-sentinel-syslog-event-source",
}


def load_roles():
Expand Down Expand Up @@ -57,6 +54,13 @@ def save_roles(roles):
print(f"Updated {len(sorted_roles)} roles in {ROLES_FILE}")


def save_role_repositories(repositories):
"""Save GitHub repository slugs for roles whose Galaxy names differ."""
filepath = os.path.join(REPO_ROOT, ROLE_REPOSITORIES_FILE)
with open(filepath, "w") as f:
yaml.safe_dump(repositories, f, sort_keys=True)


def cmd_add(role_names):
"""Add one or more roles."""
roles = load_roles()
Expand Down Expand Up @@ -104,6 +108,7 @@ def cmd_list():
def cmd_sync():
"""Synchronize roles from non-archived public GitHub role repositories."""
roles = set()
role_repositories = {}
page = 1
token = os.environ.get("GITHUB_TOKEN") or os.environ.get("GH_TOKEN")

Expand Down Expand Up @@ -140,7 +145,10 @@ def cmd_sync():
if repository.get("archived") or not name.startswith(ROLE_REPOSITORY_PREFIX):
continue
repository_role = name.removeprefix(ROLE_REPOSITORY_PREFIX)
roles.add(ROLE_NAME_OVERRIDES.get(repository_role, repository_role))
role_name = repository_role.replace("-", "_")
roles.add(role_name)
if role_name != repository_role:
role_repositories[role_name] = repository_role

page += 1

Expand All @@ -151,6 +159,7 @@ def cmd_sync():
)

save_roles(roles)
save_role_repositories(role_repositories)
print(f"Synchronized roles from {GITHUB_OWNER}'s active public repositories")


Expand Down
Loading