Skip to content

Commit

Permalink
1.2.1 (#3)
Browse files Browse the repository at this point in the history
Fix monolith project type

Reorganize some documentation
  • Loading branch information
syndr authored Mar 11, 2024
1 parent 69f2dac commit 7bf1191
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 121 deletions.
126 changes: 126 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ When utilizing an image with systemd support (systemd packages are installed, et

# Using this collection

## Host Requirements

The host from which this collection is run (workstation, CI instance, etc.) must meet the following requirements:

* Molecule [is installed](https://ansible.readthedocs.io/projects/molecule/installation/) and is executable by the user.
Expand All @@ -31,6 +33,130 @@ pip install ansible-core

Docker CE can be installed by following the appropriate [installation instructions](https://docs.docker.com/engine/install/) for your OS.

## Project requirements

Roles within this collection will attempt to discover what type of project they are being utilized in. This is enabled by setting the appropriate `project_type` configuration variable to `auto`. The project type can also be explicitly specified if this is desired.

Supported project types:
* `role`
* `collection`
* `monolith`

When used with a role or collection, the Galaxy meta information for the role must be configured!

### Standalone roles

Location: `{{ role_dir }}/meta/main.yml`

For standalone roles that are not part of a collection, the minimum required information is:
```yaml
galaxy_info:
author: you
role_name: cool_stuff
```
It is however strongly recommended that the entire file be updated with the correct information for your role!
### Collections
Location: `{{ collection_dir }}/galaxy.yml`

The following minimum values should be defined:
* `namespace`
* `name`
* `version`

It is however also strongly recommended that the entire file be updated with the correct information for your collection!

### Monoliths

A monolith is a project that contains both roles and playbooks in the same directory structure.

This collection supports the following file structure:
```
.
├── ansible.cfg
├── collections
│   ├── ansible_collections
│   └── requirements.yml
├── inventory
├── molecule
│   └── default
│   ├── [...]
│   ├── collections.yml
│   ├── converge.yml
│   ├── molecule.yml
│   └── verify.yml
├── playbooks
│   ├── configure_toaster
│   │   ├── main.yml -> rick.yml
│   │   ├── README.md
│   │   ├── rick.yml
│   │   ├── tasks
│   │   └── vars
│   ├── configure_server
│   │   ├── main.yml
│   │   ├── README.md
│   │   ├── tasks
│   │   └── templates
│   ├── [...]
│   └── install_things
│   ├── install-cheese.yml
│   ├── tasks
│   └── vars
├── README.md
├── roles
│   ├── powerlevel_9000
│   │   ├── defaults
│   │   ├── meta
│   │   ├── README.md
│   │   ├── tasks
│   │   ├── tests
│   │   └── vars
│   ├── disks
│   │   ├── defaults
│   │   ├── handlers
│   │   ├── meta
│   │   ├── README.md
│   │   ├── tasks
│   │   ├── templates
│   │   ├── tests
│   │   └── vars
│   ├── [...]
│   └── something_else
└── scripts
```

When using this collection within a monolithic repository, make sure that any `ansible.cfg` configuration includes the default ansible locations, or that this collection is installed within the repository.

For example, `ansible.cfg` should contain something like:
```yaml
[defaults]
roles_path = ./roles:/usr/share/ansible/roles:/etc/ansible/roles:~/.ansible/roles
collections_path = ./collections:/usr/share/ansible/collections:~/.ansible/collections
```

or this collection should be installed locally with:
```bash
ansible-galaxy collection install -p ./collections syndr.molecule
```

or if your `collections/requirements.yml` includes this collection:
```bash
ansible-galaxy collection install -p ./collections -r ./collections/requirements.yml
```

#### Testing roles within a monolithic project

When configuring molecule testing for individual roles within a monolithic project (creating a `roles/<role_name>/molecule` directory), take care _not_ to name the scenario "default", as there is already a "default" scenario for the monolithic project itself if you have created `molecule/default` as described above! Instead, name your role scenario with a unique name.

```bash
ROLE_NAME=your_role
mkdir -p molecule/role-$ROLE_NAME
wget -P molecule/role-$ROLE_NAME https://raw.githubusercontent.com/syndr/ansible-collection-molecule/main/roles/init/files/init.yml
ansible-playbook molecule/role-$ROLE_NAME/init.yml
```

# Contributing

Pull requests are welcomed!
Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace: syndr
name: molecule

# The version of the collection. Must be compatible with semantic versioning
version: 1.2.0
version: 1.2.1

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down
118 changes: 1 addition & 117 deletions roles/prepare_controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,123 +15,7 @@ Project formats currently supported by this role are:
* `collection`
* `monolith`

## Galaxy meta configuration

When used with a role or collection, the Galaxy meta information for the role must be configured!


### Standalone roles

Location: `{{ role_dir }}/meta/main.yml`

For standalone roles that are not part of a collection, the minimum required information is:
```yaml
galaxy_info:
author: you
role_name: cool_stuff
```
It is however strongly recommended that the entire file be updated with the correct information for your role!
### Collections
Location: `{{ collection_dir }}/galaxy.yml`

The following minimum values should be defined:
* `namespace`
* `name`
* `version`

It is however also strongly recommended that the entire file be updated with the correct information for your collection!

### Monoliths

A monolith is a project that contains both roles and playbooks in the same directory structure.

This collection supports the following file structure:
```
.
├── ansible.cfg
├── collections
│   ├── ansible_collections
│   └── requirements.yml
├── inventory
├── molecule
│   └── default
│   ├── [...]
│   ├── collections.yml
│   ├── converge.yml
│   ├── molecule.yml
│   └── verify.yml
├── playbooks
│   ├── configure_toaster
│   │   ├── main.yml -> rick.yml
│   │   ├── README.md
│   │   ├── rick.yml
│   │   ├── tasks
│   │   └── vars
│   ├── configure_server
│   │   ├── main.yml
│   │   ├── README.md
│   │   ├── tasks
│   │   └── templates
│   ├── [...]
│   └── install_things
│   ├── install-cheese.yml
│   ├── tasks
│   └── vars
├── README.md
├── roles
│   ├── powerlevel_9000
│   │   ├── defaults
│   │   ├── meta
│   │   ├── README.md
│   │   ├── tasks
│   │   ├── tests
│   │   └── vars
│   ├── disks
│   │   ├── defaults
│   │   ├── handlers
│   │   ├── meta
│   │   ├── README.md
│   │   ├── tasks
│   │   ├── templates
│   │   ├── tests
│   │   └── vars
│   ├── [...]
│   └── something_else
└── scripts
```

When using this collection within a monolithic repository, make sure that any `ansible.cfg` configuration includes the default ansible locations, or that this collection is installed within the repository.

For example, `ansible.cfg` should contain something like:
```yaml
[defaults]
roles_path = ./roles:/usr/share/ansible/roles:/etc/ansible/roles:~/.ansible/roles
collections_path = ./collections:/usr/share/ansible/collections:~/.ansible/collections
```

or this collection should be installed locally with:
```bash
ansible-galaxy collection install -p ./collections syndr.molecule
```

or if your `collections/requirements.yml` includes this collection:
```bash
ansible-galaxy collection install -p ./collections -r ./collections/requirements.yml
```

#### Testing roles within a monolithic project

When configuring molecule testing for individual roles within a monolithic project (creating a `roles/<role_name>/molecule` directory), take care _not_ to name the scenario "default", as there is already a "default" scenario for the monolithic project itself if you have created `molecule/default` as described above! Instead, name your role scenario with a unique name.

```bash
ROLE_NAME=your_role
mkdir -p molecule/role-$ROLE_NAME
wget -P molecule/role-$ROLE_NAME https://raw.githubusercontent.com/syndr/ansible-collection-molecule/main/roles/init/files/init.yml
ansible-playbook molecule/role-$ROLE_NAME/init.yml
```
Specific requirements for each project type can be found in the [collection documentation](../../README.md#project-requirements).

Role Variables
--------------
Expand Down
5 changes: 2 additions & 3 deletions roles/prepare_controller/tasks/monolith.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

- name: Check directory paths
ansible.builtin.stat:
path: "{{ __prepare_controller_item }}"
path: "{{ prepare_controller_project_dir }}/{{ __prepare_controller_item }}"
register: __prepare_controller_filepath_stat
loop:
- collections
Expand All @@ -21,8 +21,7 @@
that: __prepare_controller_item.stat.exists is true
fail_msg: Required project file layout not found! See README!
success_msg: Path is found
loop: "{{ __prepare_controller_stat.results }}"
loop: "{{ __prepare_controller_filepath_stat.results }}"
loop_control:
loop_var: __prepare_controller_item
label: "{{ __prepare_controller_item.item }}"

0 comments on commit 7bf1191

Please sign in to comment.