Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to ansible collection #149

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:

env:
galaxy-name: "dokku_bot.ansible_dokku"
galaxy-name: "dokku_bot.dokku_collection"


jobs:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For general hints see the project-wide [contributing guide](https://github.com/d

* The role's directory layout follows [standard Ansible practices](https://galaxy.ansible.com/docs/contributing/creating_role.html#roles).
* Besides the yaml-based ansible instructions, the role includes several new Ansible *modules* in the `library/` folder (e.g. `dokku_app`).
* The `README.md` of this repository is auto-generated: do *not* edit it directly.
* The `README.md` of this repository is auto-generated: do *not* edit it directly.
In order to update it, run `make generate`.

## Setting up a test environment
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: clean
clean:
rm -f README.md defaults/main.yml ../dokku.tar.gz
rm -f README.md roles/install_dokku/defaults/main.yml ../dokku.tar.gz

.PHONY: release
release: generate
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ used to interface with dokku from your own Ansible playbooks.
- [Requirements](#requirements)
- [Dependencies](#dependencies)
- [Role Variables](#role-variables)
- [Libraries](#libraries)
- [Plugins](#Plugins)
- [Example Playbooks](#example-playbooks)
- [Contributing](#contributing)
- [License](#license)
Expand All @@ -39,7 +39,7 @@ Supported Platforms

- geerlingguy.docker ansible role
- nginxinc.nginx ansible role
- Dokku (for library usage)
- Dokku (for plugin usage)

## Role Variables

Expand Down Expand Up @@ -154,7 +154,7 @@ Scheduled for deletion after 07/2021. Use `dokku_packages_state` instead.
- description: The version of sshcommand to install.
Scheduled for deletion after 07/2021. Use `dokku_packages_state` instead.

## Libraries
## Plugins

### dokku_acl_app

Expand Down Expand Up @@ -1044,7 +1044,7 @@ Manage storage for dokku applications
---
- hosts: all
roles:
- dokku_bot.ansible_dokku
- dokku_bot.dokku_collection
```

### Installing Plugins
Expand All @@ -1053,7 +1053,7 @@ Manage storage for dokku applications
---
- hosts: all
roles:
- dokku_bot.ansible_dokku
- dokku_bot.dokku_collection
vars:
dokku_plugins:
- name: clone
Expand All @@ -1068,7 +1068,7 @@ Manage storage for dokku applications
---
- hosts: all
roles:
- dokku_bot.ansible_dokku
- dokku_bot.dokku_collection
tasks:
- name: dokku apps:create inflector
dokku_app:
Expand All @@ -1086,7 +1086,7 @@ Manage storage for dokku applications
---
- hosts: all
roles:
- dokku_bot.ansible_dokku
- dokku_bot.dokku_collection
- geerlingguy.swap
vars:
# If you are running dokku on a small VPS, you'll most likely
Expand Down
34 changes: 19 additions & 15 deletions bin/generate
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ def section_header(text, level=1):
return "{0} {1}".format("#" * level, text)


def get_libraries(role_path):
libraries_path = os.path.join(role_path, "library")
def get_plugins(role_path):
plugins_path = os.path.join(role_path, "plugins", "modules")
files = []
for (dirpath, dirnames, filenames) in os.walk(libraries_path):
for (dirpath, dirnames, filenames) in os.walk(plugins_path):
files.extend(filenames)
break

data = {}
for f in files:
data[f] = {}
M = ast.parse("".join(open(os.path.join(libraries_path, f))))
M = ast.parse("".join(open(os.path.join(plugins_path, f))))
for child in M.body:
if isinstance(child, ast.Assign):
for t in child.targets:
Expand Down Expand Up @@ -53,7 +53,7 @@ def add_table_of_contents(text):
"- [Requirements](#requirements)",
"- [Dependencies](#dependencies)",
"- [Role Variables](#role-variables)",
"- [Libraries](#libraries)",
"- [Plugins](#Plugins)",
"- [Example Playbooks](#example-playbooks)",
"- [Contributing](#contributing)",
"- [License](#license)",
Expand All @@ -63,18 +63,18 @@ def add_table_of_contents(text):
return text


def add_libraries(text, role_path):
libraries = get_libraries(role_path)
def add_plugins(text, role_path):
plugins = get_plugins(role_path)

def chosen(choice, default):
if choice == default:
return "**{0}** (default)".format(choice)
return "{0}".format(choice)

library_keys = sorted(libraries.keys())
text.append(section_header("Libraries", 2))
for library in library_keys:
data = libraries[library]
plugin_keys = sorted(plugins.keys())
text.append(section_header("Plugins", 2))
for plugin in plugin_keys:
data = plugins[plugin]
options = [
"|Parameter|Choices/Defaults|Comments|",
"|---------|----------------|--------|",
Expand Down Expand Up @@ -152,7 +152,7 @@ def add_requirements(text, meta, defaults):
"- {0} ansible role".format(dependency["role"])
for dependency in meta["dependencies"]
]
dependencies.append("- Dokku (for library usage)")
dependencies.append("- Dokku (for plugin usage)")
text.append("\n".join(dependencies))

return text
Expand Down Expand Up @@ -214,7 +214,9 @@ def generate_readme():
meta = yaml.load(f.read(), Loader=yaml.SafeLoader)

defaults = {}
defaults_file = os.path.join(role_path, "defaults", "main.yml")
defaults_file = os.path.join(
role_path, "roles", "install_dokku", "defaults", "main.yml"
)
with open(defaults_file) as f:
defaults = yaml.load(f.read(), Loader=yaml.SafeLoader)

Expand All @@ -231,7 +233,7 @@ def generate_readme():
text = add_table_of_contents(text)
text = add_requirements(text, meta, defaults)
text = add_variables(text, role_path)
text = add_libraries(text, role_path)
text = add_plugins(text, role_path)
text = add_examples(text, role_path)

text.append(section_header("Contributing", 2))
Expand Down Expand Up @@ -262,7 +264,9 @@ def generate_defaults():
continue
defaults[variable] = config["default"]

defaults_file = os.path.join(role_path, "defaults", "main.yml")
defaults_file = os.path.join(
role_path, "roles", "install_dokku", "defaults", "main.yml"
)
with open(defaults_file, "w") as f:
f.write(yaml.dump(defaults, explicit_start=False))

Expand Down
8 changes: 4 additions & 4 deletions example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ examples:
---
- hosts: all
roles:
- dokku_bot.ansible_dokku
- dokku_bot.dokku_collection

- name: Installing Plugins
example: |
---
- hosts: all
roles:
- dokku_bot.ansible_dokku
- dokku_bot.dokku_collection
vars:
dokku_plugins:
- name: clone
Expand All @@ -24,7 +24,7 @@ examples:
---
- hosts: all
roles:
- dokku_bot.ansible_dokku
- dokku_bot.dokku_collection
tasks:
- name: dokku apps:create inflector
dokku_app:
Expand All @@ -39,7 +39,7 @@ examples:
---
- hosts: all
roles:
- dokku_bot.ansible_dokku
- dokku_bot.dokku_collection
- geerlingguy.swap
vars:
# If you are running dokku on a small VPS, you'll most likely
Expand Down
28 changes: 28 additions & 0 deletions galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# See https://docs.ansible.com/ansible/latest/dev_guide/collections_galaxy_meta.html

namespace: dokku_bot

# The name of the collection. Has the same character restrictions as 'namespace'
name: dokku_collection

# The version of the collection. Must be compatible with semantic versioning
version: 1.0.0
readme: README.md
authors:
- Dokku (https://github.com/dokku)
description: Collection for managing dokku with ansible
license_file: LICENSE.md

# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character
# requirements as 'namespace' and 'name'
tags: []

# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
# collection label 'namespace.name'. The value is a version range
# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version
# range specifiers can be set and are separated by ','
dependencies: {}

repository: https://github.com/dokku/ansible-dokku
homepage: https://github.com/dokku/ansible-dokku
issues: https://github.com/dokku/ansible-dokku/issues
7 changes: 6 additions & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'

- name: Install gpg-agent
apt:
name:
- gpg-agent

roles:
- role: dokku_bot.ansible_dokku # noqa
- role: dokku_bot.dokku_collection.install_dokku # noqa
vars:
dokku_plugins:
- name: global-cert
Expand Down
Loading