-
Notifications
You must be signed in to change notification settings - Fork 1
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
Move molecule config for playbooks into playbooks/
folder
#43
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7e8c084
Move playbook molecule configuration into playbook/ folder
p-j-smith 84000d5
rename tests folder to molecule_configs
p-j-smith 30f6bb8
Update readme with new instructions for testing playbooks
p-j-smith c9c2c77
update paths to molecule base configs
p-j-smith e435dcc
Add a README for the molecule base configs
p-j-smith 8ba9679
Move the shared prepare playbook into the monitoring resources
p-j-smith 27a8082
Add a README for the playbooks
p-j-smith 83d0366
update path to resources in playbook molecule configs
p-j-smith 16ba5e1
Use correct path to playbook molecule scenarios in workflows
p-j-smith f231ac4
create centos7 and rocky9 groups for the monitoring molecule setup
p-j-smith bb9f25b
use hardcoded container names in monitoring verify playbook
p-j-smith 07cbcc3
Fix veryfiy checks that containers are running for monitoring playbook
p-j-smith 6fcd951
Check that the node exporter service is running
p-j-smith 9048906
Loop over container names to verify they exist and are running
p-j-smith 9a2d911
fix various README typos
p-j-smith da2b54e
Check containre state is Running, rather than status (which may be re…
p-j-smith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# mirsg.infrastructure Molecule base configurations | ||
|
||
This folder contains base configurations for running tests with [Ansible | ||
Molecule](https://ansible.readthedocs.io/projects/molecule/). | ||
|
||
The base configuration is merged with - and can be overridden by - the scenario | ||
configuration. To use a base configuration, specify the path to one of the files | ||
in this directory. For example, to use the CentOS 7 base configuration: | ||
|
||
``` | ||
molecule --base-config <path to molecule_configs>/centos7_base_config.yml | ||
``` |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# mirsg.infrastructure playbooks | ||
|
||
This collection contains playbooks for deploying XNAT and setting up monitoring of servers. | ||
|
||
## Molecule setup | ||
|
||
This collection is tested using Ansible Molecule. | ||
|
||
Each playbook has its own Molecule configuration, which can be found in the | ||
`ansible_collections/mirsg/infrastructure/playbooks/molecule/` folder. | ||
Molecule base configurations are used to reduce to amount | ||
of duplication in the setup for testing each playbook. There are two base configurations | ||
that correspond to two [Molecule | ||
scenarios](https://ansible.readthedocs.io/projects/molecule/getting-started/#molecule-scenarios) | ||
one for testing on CentOS 7 and another for testing on RockyLinux 9. The base configurations | ||
are in the `ansible_collections/mirsg/infrastructure/molecule_configs` folder. | ||
|
||
## Adding a new playbook | ||
|
||
To add a new playbook to this collection, you will need to: | ||
|
||
1. add the playbook to the `playbooks/` folder | ||
2. add a molecule configuration for the playbook to the `playbooks/molecule/` folder | ||
3. add a workflow for the playbook to the `.github/workflows` folder | ||
|
||
### Add a new playbook to the playbooks folder | ||
|
||
The playbooks in an Ansible Collection are the same as any other playbook - no special | ||
setup is required. If you create a playbook | ||
`ansible_collections/mirsg/infrastructure/playbooks/my_playbook.yml`, you will be able to | ||
run the playbook using `ansible-playbook`: | ||
|
||
```bash | ||
ansible-playbook mirsg.infrastructure.my_playbook | ||
``` | ||
|
||
or include it within another playbook: | ||
|
||
```yaml | ||
- name: Run my_playbook | ||
ansible.builtin.import_playbook: mirsg.infrastructure.my_playbook | ||
``` | ||
|
||
### Add a molecule configuration | ||
|
||
Create CentOS 7 and RockyLinux 9 scenarios for your playbook in | ||
`ansible_collections/mirsg/infrastructure/playbooks/molecule`. See | ||
the `mirsg.infrastructure.install_monitoring` | ||
[CentOS 7](./molecule/centos7_monitoring/) and | ||
[RockyLinux 9](./molecule/rocky9_monitoring/) scenarios for an example | ||
configuration. | ||
|
||
Add the `converge.yml` playbook to a shared `resources` subfolder: | ||
`molecule/resources/my_playbook/converge.yml`. | ||
|
||
If necessary, add inventory `group_vars` to the shared `resources` subfolder: | ||
`molecule/resources/my_playbook/inventory/group_vars`. for your playbook. | ||
|
||
You may also need to add `prepare` or `verify` playbooks. These can be added | ||
to the the same shared `resources` folder. | ||
|
||
You will need to update the `molecule.yml` configuration file with the correct paths | ||
to these playbooks. | ||
|
||
### Add a GitHub Workflow | ||
|
||
You should add a GitHub workflow for your new playbook to `.github/workflows/molecule-my-playbook.yml`. | ||
The workflow should follow this format: | ||
|
||
```yaml | ||
name: Test my_playbook | ||
on: | ||
pull_request: | ||
paths: | ||
- "playbooks/my_playbook.yml" | ||
- ".github/workflows/molecule-role-used-in-playbook.yml" | ||
|
||
jobs: | ||
molecule-my_playbook: | ||
uses: ./.github/workflows/molecule.yml | ||
with: | ||
tests-path: ansible_collections/mirsg/infrastructure/playbooks | ||
``` | ||
|
||
This uses the [`.github/workflows/molecule.yml` reusable workflow](.github/workflows/molecule.yml) to run | ||
molecule on the relevant role. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
- name: Create monitoring server certs | ||
hosts: monitoring_host | ||
become: true | ||
gather_facts: true | ||
roles: | ||
- role: mirsg.infrastructure.ssl_certificates | ||
vars: | ||
ssl_certificate: "{{ monitoring_server_ssl_certificate }}" | ||
|
||
- name: Install Monitoring Service | ||
ansible.builtin.import_playbook: mirsg.infrastructure.install_monitoring |
8 changes: 8 additions & 0 deletions
8
playbooks/molecule/resources/monitoring/inventory/group_vars/all.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
ansible_cache_dir: "{{ lookup('env', 'HOME') }}/ansible_persistent_files" | ||
|
||
external_storage_drive: "/storage/molecule" | ||
selinux_enabled: false | ||
|
||
# mirsg.infrastructure.provision | ||
server_locale: "en_GB.UTF-8" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
- name: Setup for the firewall | ||
hosts: all | ||
gather_facts: true | ||
tasks: | ||
- name: Install firewalld | ||
ansible.builtin.package: | ||
name: firewalld | ||
state: present | ||
|
||
- name: Change firewalld backend to iptables | ||
ansible.builtin.lineinfile: | ||
path: /etc/firewalld/firewalld.conf | ||
regexp: "^FirewallBackend=" | ||
line: FirewallBackend=iptables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
- name: Check monitoring host | ||
hosts: monitoring_host | ||
become: true | ||
gather_facts: true | ||
vars: | ||
container_names: | ||
- alertmanager | ||
- blackbox-exporter | ||
- cadvisor | ||
- grafana | ||
- nginx | ||
- prometheus | ||
tasks: | ||
- name: Get container info | ||
community.docker.docker_container_info: | ||
name: "{{ item }}" | ||
loop: "{{ container_names }}" | ||
register: container_info | ||
|
||
- name: Check containers exist and are running | ||
ansible.builtin.assert: | ||
that: | ||
- item.exists | ||
- item.container.State.Running | ||
loop: "{{ container_info.results }}" | ||
|
||
- name: Check monitoring client | ||
hosts: monitoring_client | ||
become: true | ||
gather_facts: true | ||
tasks: | ||
- name: Populate service facts | ||
ansible.builtin.service_facts: | ||
|
||
- name: Ensure that node exporter has started | ||
ansible.builtin.assert: | ||
that: | ||
- "{{ 'node_exporter.service' in ansible_facts.services }}" | ||
- ansible_facts.services['node_exporter.service'].state == "running" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
playbooks/molecule/resources/xnat/inventory/group_vars/centos7.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
# mirsg.infrastructure.install_python | ||
install_python: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above about |
||
version: "2" | ||
pip_version: "20.3.4" | ||
pip_executable: "pip" | ||
system_packages: | ||
- python | ||
- python-pip | ||
- python-setuptools | ||
pip_packages: | ||
- cryptography |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason not to use the
check_default_version
task in theinstall_python
role instead of adding thecentos7
androcky9
groups (which are in bothresources/monitoring
andresources/xnat
) to set theinstall_python
var?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @paddyroddy was having issues with those pre-tasks when trying to use a different image for testing? And I thought it seemed easier to follow to have variables defined in the group vars rather than tasks that set them, but happy to change it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I didn't realise. It's just that the group vars are duplicated for both sets of playbook tests but let's leave it as-is for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yeah I thought about that. We could have a single inventory for both, and combine the scenarios so we have
centos7
androcky9
scenarios rather than playbook-specific ones. Then in the converge etc. playbook etc. tag the tasks like we were doing for the roles. But that felt like a lot of changes for an already large pr!