Skip to content

Commit 16190b5

Browse files
Add README and first Ansible role skeleton: role_default
Thanks to @Meissnerim for working on the code, additional review and input.
0 parents  commit 16190b5

File tree

23 files changed

+620
-0
lines changed

23 files changed

+620
-0
lines changed

LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2020 Foundata GmbH, https://foundata.com
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

NOTICE

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
NOTE: Any derivative works that you distribute must include a readable copy of
2+
the attribution notices contained in this file (cf. Apache License 2.0;
3+
§ 4.4).
4+
5+
6+
I. Foundata
7+
8+
This Ansible resource is based on the work of Foundata [1]. If you like it,
9+
you might buy them a coffee [2] or have a look at their website.
10+
11+
[1] https://foundata.com/
12+
[2] https://buy-me-a.coffee/ansible-skeletons/

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Ansible (Galaxy) Skeletons
2+
3+
This repository contains different skeletons / blueprints to kickstart the creation of new [roles](https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html) and [collections](https://docs.ansible.com/ansible/devel/dev_guide/developing_collections.html).
4+
5+
6+
7+
## Table of contents
8+
9+
* [Usage](#usage)
10+
* [Description of provided skeletons](#description-of-provided-skeletons)
11+
* [`role_default`](#role_default)
12+
* [Author information](#author-information)
13+
* [License, Copyright](#license-copyright)
14+
15+
16+
17+
## Usage
18+
19+
1. Clone this repository:
20+
```sh
21+
git clone https://github.com/foundata/ansible-skeletons.git
22+
```
23+
2. Call `ansible-galaxy` and provide the path to the skeleton to use as well as a role name:
24+
```sh
25+
ansible-galaxy role init --role-skeleton "./ansible-skeletons/role_default" "name_of_your_role"
26+
```
27+
* `name_of_your_role` has to follow [some rules](https://galaxy.ansible.com/docs/contributing/creating_role.html#role-names) and is should consist of `a-z`, `0-9` and `_` only.
28+
* Adapt the `--role-skeleton` parameter value if you want to use another skeleton than `role_default`. You can find a description of the available ones below.
29+
3. Have a look at the created `./name_of_your_role/FIXME.md` to get further instructions.
30+
31+
32+
33+
## Description of provided skeletons
34+
35+
The following lists gives an overview over the available skeletons. You can also have a look into the sub-directories of this repository to look at their code (even though the source might be partially hard to read. There is [Jinja](https://palletsprojects.com/p/jinja/) code which will be processed by `ansible-galaxy role init` to get the final files).
36+
37+
38+
39+
### `role_default`
40+
41+
A general purpose skeleton to create new Ansible Galaxy roles. Main features:
42+
43+
* Init tasks to check the execution environment based on the role's meta data
44+
* Easy management of role parameters and belonging [`assert`](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/assert_module.html) rules for validation (see `{{ role_name }}_required_vars` in [`role_default/vars/main.yml.j2`](./role_default/vars/main.yml.j2) for more information).
45+
* Separation of logical task groups
46+
47+
48+
49+
## Author information
50+
51+
This project was created and is maintained by:
52+
53+
* [Andreas Haerter](https://andreashaerter.com/) ([Foundata](https://foundata.com/))
54+
* [Frederik Meissner](https://meissner.im/) ([Foundata](https://foundata.com/))
55+
56+
If you like it, you might [buy us a coffee](https://buy-me-a.coffee/ansible-skeletons/).
57+
58+
59+
60+
## License, Copyright
61+
62+
[Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) if not mentioned otherwise. See [`LICENSE`](./LICENSE) and [`NOTICE`](./NOTICE) for details.

role_default/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# do not ignore files used to keep empty directories
2+
!.gitkeep
3+
4+
### Ansible ###
5+
*.retry

role_default/FIXME.md.j2

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# FIXME/TODO (you should delete this file after reading / completing the tasks)
2+
3+
A (maybe incomplete but hopefully useful) list of things to do after creating a
4+
new role based on the skeleton, especially before releasing anything:
5+
6+
1. **Update author information** (and/or company and/or year) in
7+
* [`LICENSE`](./LICENSE) → First line
8+
* [`meta/main.yml`](./meta/main.yml) → `galaxy_info:` → `author`, `company`
9+
and URLs if fitting
10+
* The "[`README.md`: Author Information](./README.md#author-information)" section
11+
2. **Update requirements information** in the "[`README.md`: Requirements](./README.md#requirements)"
12+
section and list any pre-requisites that may not be covered by Ansible
13+
itself, e.g.:
14+
* DNS names to configure, firewall ports to open
15+
* [SELinux](https://en.wikipedia.org/wiki/Security-Enhanced_Linux)
16+
* has to be disabled.
17+
* is supported in "Permissive" mode only.
18+
* is supported in "Enforcing" as well as in "Permissive" mode.
19+
3. **Update dependency information**:
20+
* In the "[`README.md`: Dependencies](./README.md#dependencies)" section:
21+
* A list of other roles hosted on Galaxy should go here
22+
* Plus any details in regards to parameters that may need to be set for
23+
other roles or variables that are used from other roles.
24+
* [`meta/main.yml`](./meta/main.yml) -> `dependencies:`
25+
4. **Update compatibility information**:
26+
* In the "[`README.md`: Compatibility](./README.md#compatibility)" section:
27+
* maybe you want to mention the main platform / first class citizens.
28+
* or if things where tested on container / VM / bare metal
29+
* [`meta/main.yml`](./meta/main.yml) -> `platforms:`
30+
* There is [a list of platforms](https://galaxy.ansible.com/api/v1/platforms/)
31+
* The list is paginated. You can also search for e.g. Fedora by adding
32+
`?name__icontains=fedora`.
33+
5. **Tests / [Molecule](https://molecule.readthedocs.io/en/latest/)**: delete the
34+
whole `./molecule` directory if you do not want to provide tests at this point
35+
in time or:
36+
* [`molecule/default/molecule.yml`](./molecule/default/molecule.yml): Define `driver` and `platforms` for your tests
37+
* [`molecule/default/tests/`](./molecule/default/tests/): Write test cases (Example: [`molecule/default/tests/test_default.py`](./molecule/default/tests/test_default.py))
38+
6. **Misc things**
39+
* [`meta/main.yml`](./meta/main.yml): Remove unneeded, commented keys. See
40+
the following for more information if you are unsure what they do or if
41+
you even need more:
42+
* <https://galaxy.ansible.com/docs/contributing/creating_role.html#role-metadata>
43+
* <https://github.com/ansible/ansible/blob/devel/lib/ansible/playbook/role/metadata.py>
44+
* <https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py>
45+
* You may want to add a section with useful weblinks to describe what the
46+
role is managing or other useful resources:
47+
```markdown
48+
## Further reading
49+
50+
* [Official Example website](http://example.com/]
51+
* [Wikipedia: Example](http://en.wikipedia.org/wiki/Example)
52+
```
53+
* Add example playbook(s) to the "[`README.md`: Example Playbook](./README.md#example-playbook)" section

role_default/LICENSE.j2

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright YYYY {{ company }}, {{ author }} <email@example.com>
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

role_default/NOTICE.j2

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
NOTE: Any derivative works that you distribute must include a readable copy of
2+
the attribution notices contained in this file (cf. Apache License 2.0;
3+
§ 4.4).
4+
5+
6+
I. Foundata
7+
8+
This Ansible role is based on the work of Foundata [1]. If you like it,
9+
you might buy them a coffee [2] or have a look at their website.
10+
11+
[1] https://foundata.com/
12+
[2] https://buy-me-a.coffee/ansible-skeletons/

role_default/README.md.j2

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# `{{ role_name }}`
2+
3+
{{ description }}
4+
5+
6+
7+
## Table of contents
8+
9+
* [Requirements](#requirements)
10+
* [Role variables](#role-variables)
11+
* [Dependencies](#dependencies)
12+
* [Example playbook](#example-playbook)
13+
* [Supported tags](#supported-tags)
14+
* [Compatibility](#compatibility)
15+
* [License, copyright](#license-copyright)
16+
* [Author information](#author-information)
17+
18+
19+
20+
## Requirements
21+
22+
There are no special requirements not covered by Ansible itself.
23+
24+
25+
26+
## Role variables
27+
28+
See [`defaults/main.yml`](./defaults/main.yml) for all available role parameters and their description. [`vars/main.yml`](./vars/main.yml) contains variables you should not override (but their descrption might be interesting).
29+
30+
Additionally, there are variables read from other roles and/or the global scope (e.g. host or group vars) as follows:
31+
32+
* None right now.
33+
34+
35+
36+
## Dependencies
37+
38+
See `dependencies` in [`meta/main.yml`](./meta/main.yml).
39+
40+
41+
42+
## Example playbook
43+
44+
None right now.
45+
46+
47+
48+
## Supported tags
49+
50+
It might be useful and faster to only call parts of the role by using tags:
51+
52+
* `setup`: Setup tasks like package installations (mostly one-time).
53+
* `config`: Creates / updates configuration files and related resources.
54+
* `service`: Creates / updates service related files and manages their state.
55+
* `always`: Preparation task at start as well as clean-up task during completion. May be called explicitly to force a cleanup (for example leftovers when there was an unexpected interruption).
56+
57+
58+
59+
## Compatibility
60+
61+
See `platforms` in [`meta/main.yml`](./meta/main.yml).
62+
63+
64+
65+
## License, copyright
66+
67+
[Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0). See [`LICENSE`](./LICENSE) and [`NOTICE`](./NOTICE) for details.
68+
69+
70+
71+
## Author information
72+
73+
This role was created by {{author}} and is based on an [Ansible skeleton](https://github.com/foundata/ansible-skeletons) by [Foundata](https://foundata.com/). If you like it, you might [buy them a coffee](https://buy-me-a.coffee/ansible-skeletons/).

role_default/defaults/main.yml.j2

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Default values of the role.
2+
#
3+
# Easy to override (as they have a low precedence) and most commonly used to
4+
# enable a user to modify the role behavior. There should be a comment above
5+
# each value to explain its purpose.
6+
7+
---
8+
9+
# String. Controls if the managed resources shall be "present" or "absent".
10+
# Defaults to "present". Possible values:
11+
#
12+
# * "present": Needed components like software packages will be installed and
13+
# configured.
14+
# * "absent": Modifications (if any) will be reverted as good as possible (e.g.
15+
# removal of packages, created users, services, changed log settings, …).
16+
{{ role_name }}_state: "present"
17+
18+
19+
# Boolean. If set to true, any managed package gets upgraded on each Ansible
20+
# run when the package provider is able to find a newer version than the
21+
# present one. Defaults to false.
22+
{{ role_name }}_autoupgrade: false
23+
24+
25+
# String. Defines the status of service(s). Defaults to "enabled". Possible
26+
# values:
27+
#
28+
# * "enabled": Service is running and will start automatically at boot.
29+
# * "disabled": Service is stopped and will not start automatically at boot.
30+
# * "running": Service is running but will not start automatically at boot.
31+
# You can use this to start a service on the first Ansible rather
32+
# automatically at boot.
33+
# * "unmanaged": Service will not be started at boot time and Ansible does not
34+
# care whether the service is running or not. Mostly useful when services
35+
# are monitored and managed by another system than Ansible.
36+
#
37+
# The singular form ("service") is used for the sake of convenience. Of course,
38+
# the defined status affects all services if more than one is managed.
39+
{{ role_name }}_service_state: "enabled"
40+
41+
42+
# FIXME Description of a very important example parameter
43+
# {{ role_name }}_example_parameter_variable: true

role_default/files/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)