Skip to content

Commit

Permalink
Bundle playbooks in collection
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmdln committed Mar 23, 2024
1 parent c00ee8a commit b53a4f4
Show file tree
Hide file tree
Showing 32 changed files with 316 additions and 291 deletions.
6 changes: 4 additions & 2 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C. Maudlin <[email protected]>
# Copyright (c) 2024 Johnathan C. Maudlin <[email protected]>
---
exclude_paths:
- .github
- .github/
- .vscode/
skip_list:
- meta-runtime[unsupported-version]
- no-changed-when
- no-handler
- no-tabs
6 changes: 1 addition & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C. Maudlin <[email protected]>
# Copyright (c) 2024 Johnathan C. Maudlin <[email protected]>

root = true

Expand All @@ -21,7 +21,3 @@ tab_width = 2
[*.{ansible-,yaml}lint]
indent_size = 2
tab_width = 2

[Vagrantfile]
indent_size = 2
tab_width = 2
8 changes: 3 additions & 5 deletions .github/workflows/galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C. Maudlin <[email protected]>
# Copyright (c) 2024 Johnathan C. Maudlin <[email protected]>
---
name: Release

on:
push:
tags:
- "*"
tags: ["*"]

jobs:
release:
Expand All @@ -17,8 +16,7 @@ jobs:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: "3.11"
with: { python-version: "3.11" }

- name: Install Ansible
run: pip install ansible-core
Expand Down
16 changes: 6 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C. Maudlin <[email protected]>
# Copyright (c) 2024 Johnathan C. Maudlin <[email protected]>
---
name: lint

on:
pull_request:
branches:
- "**"
paths-ignore:
- "**.md"
branches: ["**"]
paths-ignore: ["**.md"]
push:
branches:
- "**"
paths-ignore:
- "**.md"
branches: ["**"]
paths-ignore: ["**.md"]
workflow_dispatch:

jobs:
Expand All @@ -27,7 +23,7 @@ jobs:
matrix:
linter: [ansible-lint, mypy, ruff]
os: [ubuntu-latest]
python: ["3.9", "3.10", "3.11"]
python: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
Expand Down
44 changes: 18 additions & 26 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,49 +1,41 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C. Maudlin <[email protected]>
# Copyright (c) 2024 Johnathan C. Maudlin <[email protected]>

# Ignore everything
*

# Include specific files
!.ansible-lint
!.editorconfig
!.gitignore
!.prettierrc.yml
!.yamllint
!CHANGELOG.md
!galaxy.yml
!LICENSE
!pyproject.toml
!README.md
!site-check.yml
!site-mail.yml
!site-pkg.yml
!site-syspatch.yml
!site-sysupgrade.yml
!tox.ini

# Include files from subdirectories
# Include directories
!.github/
!.github/workflows/
!.github/workflows/*.yml

!.vscode/
!.vscode/extensions.json
!.vscode/settings.json

!inventory/
!inventory/localhost.yml

!meta/
!meta/runtime.yml

!playbooks/
!playbooks/*.yml
!plugins/
!plugins/modules/
!plugins/modules/*.py

!roles/
!roles/**/
!roles/**/*.j2
!roles/**/*.md
!roles/**/*.yml
!roles/**/templates/**/*.j2

# Include files
!.ansible-lint
!.editorconfig
!.gitignore
!.prettierrc.yml
!.yamllint
!CHANGELOG.md
!galaxy.yml
!LICENSE
!pyproject.toml
!README.md
!tox.ini
5 changes: 2 additions & 3 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C. Maudlin <[email protected]>
# Copyright (c) 2024 Johnathan C. Maudlin <[email protected]>
---
options:
editorconfig: true

overrides:
- files: "*.md"
options:
tabWidth: 2
options: { tabWidth: 2 }
5 changes: 2 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// SPDX-License-Identifier: ISC
//
// Copyright (c) 2023 Johnathan C. Maudlin <[email protected]>
// Copyright (c) 2024 Johnathan C. Maudlin <[email protected]>
{
"recommendations": [
"charliermarsh.ruff",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"ms-python.mypy-type-checker",
"ms-python.python",
"ms-python.vscode-pylance",
"redhat.ansible",
"redhat.vscode-yaml",
"samuelcolvin.jinjahtml",
"wayou.vscode-todo-highlight",
"github.vscode-github-actions",
"tamasfe.even-better-toml"
]
}
62 changes: 39 additions & 23 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// SPDX-License-Identifier: ISC
//
// Copyright (c) 2023 Johnathan C. Maudlin <[email protected]>
// Copyright (c) 2024 Johnathan C. Maudlin <[email protected]>
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.wordWrap": "on",

"evenBetterToml.formatter.columnWidth": 100,
"evenBetterToml.formatter.reorderKeys": true,
"evenBetterToml.schema.enabled": false,

"files.associations": {
".ansible-lint": "yaml",
"**/.github/workflows/galaxy.yml": "yaml",
Expand All @@ -19,35 +15,38 @@
"**/meta/**/*.yml": "ansible",
"**/tasks/**/*.yml": "ansible",
"**/vars/**/*.yml": "ansible",
"**/roles/*/templates/**/*.conf.j2": "jinja-properties",
"galaxy.yml": "ansible",
"site-*.yml": "ansible"
},
"files.exclude": {
"**/__pycache__/**": true,
"**/.mypy_cache/**": true,
"**/.ruff_cache/**": true,
"**/.pytest_cache/**": true,
"**/.tox/**": true,
"**/.venv/**": true,
"**/*.egg-info/**": true
"**/.venv/**": true
},
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,

"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
//
// Extensions
//

"ansible.python.interpreterPath": "/bin/python",

"python.formatting.provider": "black",
"python.linting.enabled": true,
"python.linting.mypyEnabled": true,
"evenBetterToml.formatter.columnWidth": 100,
"evenBetterToml.formatter.reorderKeys": true,
"evenBetterToml.schema.enabled": false,

"python.testing.pytestArgs": ["test"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,

"ruff.enable": true,
"ruff.organizeImports": true,
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.defaultFormatter": "ms-python.python"
},

"yaml.schemas": {
"https://raw.githubusercontent.com/ansible/schemas/main/f/ansible.json": [
Expand All @@ -59,5 +58,22 @@
"https://json.schemastore.org/github-workflow.json": [
"{workspaceFolder}/.github/workflows/*.yml"
]
}
},

//
// Languages
//

"[json]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
"[jsonc]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
"[markdown]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },

"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff"
},

"[yaml]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }
}
21 changes: 5 additions & 16 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C. Maudlin <[email protected]>
# Copyright (c) 2024 Johnathan C. Maudlin <[email protected]>
---
ignore: |
.mypy_cache/
.tox/
.vagrant/
.venv/
.vscode/

rules:
braces:
max-spaces-inside: 1
braces: { max-spaces-inside: 1 }
brackets: enable
colons: enable
commas: enable
comments:
level: warning
comments-indentation:
level: warning
comments: { level: warning }
comments-indentation: { level: warning }
document-end: disable
document-start:
level: warning
document-start: { level: warning }
empty-lines: enable
empty-values: disable
hyphens: enable
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ISC License

Copyright (c) 2023 Johnathan C. Maudlin <[email protected]>
Copyright (c) 2024 Johnathan C. Maudlin <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
42 changes: 13 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,27 @@ If you are looking for a hosting provider that offers OpenBSD, consider using

# Using

## Collection

```sh
# Install the collection
ansible-galaxy collection install git+https://github.com/jcmdln/ansible-collection-openbsd
```

Ansible allows running modules in an adhoc fashion for one-off tasks:

```sh
# Adhoc use of a module
ansible -i <inventory> all -m jcmdln.openbsd.pkg -a "name=htop state=present"
```

For more info, see the following:

- https://docs.ansible.com/ansible/latest/command_guide/intro_adhoc.html
# Use a provided playbook to ensure Python is installed
ansible-playbook -i <inventory> jcmdln.openbsd.python

## Playbook

```sh
# Install this collection and its dependencies
ansible-galaxy collection install .

# Create a symlink to this collection so changes don't require reinstalling
rm -fr ~/.ansible/collections/ansible_collections/jcmdln/openbsd
ln -fs $PWD ~/.ansible/collections/ansible_collections/jcmdln/openbsd

# Create an inventory
cp inventory/localhost.yml inventory/example.yml
vi inventory/example.yml

# Run a playbook
ansible-playbook -i inventory/example.yml site-check.yml
# Chain playbooks to patch hosts and update packages
ansible-playbook -i <inventory> jcmdln.openbsd.{syspatch,pkg}
```

In this example we chain playbooks to patch/upgrade hosts and update packages:
# Developing

To avoid reinstalling the collection during each change, create a symbolic link
to your user's collections path instead of installing the collection:

```sh
ansible-playbook -i inventory/example.yml \
site-check.yml site-syspatch.yml site-sysupgrade.yml site-pkg.yml
mkdir -pv $HOME/.ansible/collections/ansible_collections/jcmdln &&
rm -frv $HOME/.ansible/collections/ansible_collections/jcmdln/openbsd &&
ln -fs $PWD $HOME/.ansible/collections/ansible_collections/jcmdln/openbsd
```
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: ISC
#
# Copyright (c) 2023 Johnathan C. Maudlin <[email protected]>
# Copyright (c) 2024 Johnathan C. Maudlin <[email protected]>
---
namespace: jcmdln
name: openbsd
Expand Down
Loading

0 comments on commit b53a4f4

Please sign in to comment.