Skip to content

Commit 4dd4f9c

Browse files
Merge pull request #1 from punktDe/aar-doc
infra_role: Add aar-doc config
2 parents 11ff0c4 + 00c102c commit 4dd4f9c

File tree

7 files changed

+160
-3
lines changed

7 files changed

+160
-3
lines changed

proserver_init/infra.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def init_role(self, from_path, to_path):
4444
role_name = os.path.split(to_path)[1]
4545
config = {
4646
"role_name": role_name,
47+
"role_name_short": role_name.removeprefix("ansible-proserver-").removeprefix("ansible-")
4748
}
4849
ConfigWriter(from_path, to_path, config, flavor=None).write_configs()
4950
os.chdir(to_path)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
output_file: README.md
3+
output_mode: replace
4+
output_template: |
5+
<!-- BEGIN_ANSIBLE_DOCS -->
6+
# {{ role }}
7+
8+
{{ metadata.galaxy_info.description }}
9+
10+
## Supported Operating Systems
11+
12+
- Debian 12
13+
- Ubuntu 24.04, 22.04
14+
- FreeBSD [Proserver](https://infrastructure.punkt.de/de/produkte/proserver.html)
15+
16+
## Role Arguments
17+
18+
{% for entrypoint in argument_specs.keys() %}
19+
20+
{% if "description" in argument_specs[entrypoint] %}
21+
{%- if argument_specs[entrypoint].description is string -%}
22+
{{ argument_specs[entrypoint].description }}
23+
{% else %}
24+
{%- for line in argument_specs[entrypoint].description -%}
25+
{{ line }}
26+
27+
{% endfor -%}
28+
{% endif -%}
29+
{% endif -%}
30+
31+
{% if entrypoint_options[entrypoint] | length > 1 -%}
32+
{% for path, options in entrypoint_options[entrypoint][1:] -%}
33+
#### Options for `{{ path | reject('eq', 'main') | join(".") }}`
34+
35+
|Option|Description|Type|Required|Default|
36+
|---|---|---|---|---|
37+
{%- for name, details in options.items() %}
38+
| `{{ name }}` | {{ details.display_description }} | {{ details.display_type }} | {{ details.display_required }} | {{ details.display_default }} |
39+
{%- endfor %}
40+
41+
{% endfor -%}
42+
43+
{% endif -%}
44+
45+
{% if entrypoint in entrypoint_choices -%}
46+
{% for path, choices in entrypoint_choices[entrypoint] -%}
47+
#### Choices for {{ path | join(" > ") }}
48+
49+
|Choice|
50+
|---|
51+
{%- for item in choices %}
52+
| {{ item }} |
53+
{%- endfor %}
54+
55+
{% endfor -%}
56+
{% endif -%}
57+
{% else -%}
58+
59+
This entrypoint has no options.
60+
61+
{% endfor -%}
62+
63+
## Dependencies
64+
65+
{%- if ("dependencies" in metadata) and (metadata.dependencies | length > 0) %}
66+
{%- for dependency in metadata.dependencies %}
67+
{%- if dependency.src %}
68+
- [{{ dependency.role }}]({{ dependency.src }})
69+
{%- else %}
70+
- {{ dependency.role }}
71+
{%- endif %}
72+
{%- if dependency.when %}
73+
- **Condition**: `{{ dependency.when }}`
74+
{%- endif %}
75+
{%- endfor %}
76+
{%- else %}
77+
None.
78+
{%- endif %}
79+
80+
## Installation
81+
Add this role to the requirements.yml of your playbook as follows:
82+
```yaml
83+
roles:
84+
- name: {{ role }}
85+
src: https://github.com/punktDe/$role_name
86+
```
87+
88+
Afterwards, install the role by running `ansible-galaxy install -r requirements.yml`
89+
90+
## Example Playbook
91+
92+
```yaml
93+
- hosts: all
94+
roles:
95+
- name: $role_name_short
96+
```
97+
98+
<!-- END_ANSIBLE_DOCS -->
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
name: Generate README.md for the role
3+
4+
on:
5+
push:
6+
branches:
7+
- '**'
8+
tags-ignore:
9+
- '**'
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
readme:
17+
name: Generate README.md from argument specs
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v5
25+
26+
- name: Set up Python
27+
run: uv python install
28+
29+
- name: Install dependencies
30+
run: |
31+
uv -q venv --allow-existing --seed .venv
32+
. .venv/bin/activate
33+
uv -q pip install -r requirements.txt
34+
35+
- name: Run aar-doc
36+
run: |
37+
. .venv/bin/activate
38+
aar-doc --output-mode replace --config-file .aar-doc.yml . markdown
39+
40+
- name: Output diff
41+
run: git diff README.md
42+
43+
- name: Commit and push README
44+
run: |
45+
git config user.name github-actions
46+
git config user.email [email protected]
47+
git add README.md
48+
git diff-index --quiet HEAD || git commit -m "chore: Generate README.md"
49+
git push

proserver_init/templates/infra_role/generic/README.md.template

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
galaxy_info:
3+
author: "punkt.de"
4+
license: "MIT"
5+
role_name: $role_name_short
6+
description: "$role_name_short role for Proserver"
7+
namespace: "punktde"
8+
min_ansible_version: "2.15"
9+
platforms: []

proserver_init/templates/infra_role/generic/molecule/default/converge.yml.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
GITHUB_ACTIONS: "maybe"
66
ANSIBLE_HASH_BEHAVIOUR: merge
77
tasks:
8-
- name: "Include {{ role_name }}"
8+
- name: "Include $role_name"
99
ansible.builtin.include_role:
10-
name: "{{ role_name }}"
10+
name: "$role_name"

proserver_init/templates/infra_role/generic/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ molecule<25.2.0
55
molecule-plugins
66
yamllint
77
requests
8+
aar-doc

0 commit comments

Comments
 (0)