-
-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ansible-lint.yml): remove yaml[line-length] from skip_list (#417)
- Loading branch information
1 parent
48f019d
commit 63e981d
Showing
38 changed files
with
1,560 additions
and
86 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
.idea | ||
.venv | ||
.vscode/settings.json | ||
__pycache__/ | ||
__pycache__/ | ||
*.log | ||
molecule/**/tmp |
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 |
---|---|---|
@@ -1,15 +1,36 @@ | ||
--- | ||
- name: Molecule | Verify | All | ||
# 🚀 This playbook is designed to verify the default Molecule configuration | ||
# 🎯 The objective is to ensure that all tasks and roles are correctly set up and functioning as expected | ||
|
||
- name: Molecule.default.verify | ||
hosts: all | ||
gather_facts: true | ||
|
||
tasks: | ||
- name: Include vars of vars/main.yml | ||
# 📝 Including the main variables file for the Molecule default configuration | ||
# This file contains all the necessary variables for the playbook | ||
- name: Molecule.default.verify | Include Main Variables | ||
ansible.builtin.include_vars: | ||
file: ../../vars/main.yml | ||
|
||
- name: Molecule | Verify | Include all tests | ||
# 🔄 Including OS-specific variables | ||
# These variables are specific to the operating system on which the playbook is running | ||
- name: Molecule.default.verify | Include OS-Specific Variables | ||
ansible.builtin.include_vars: | ||
file: "../../vars/{{ ansible_os_family }}.yml" | ||
|
||
# 🔄 Including all tests for the Molecule default configuration | ||
# These tests ensure that all components of the configuration are functioning correctly | ||
- name: Molecule.default.verify | Include All Tests | ||
ansible.builtin.include_tasks: "{{ item }}" | ||
with_fileglob: | ||
- ../tests/variables/main.yml | ||
- ../tests/etcd/*.yml | ||
- ../tests/patroni/*.yml | ||
- ../tests/postgres/*.yml | ||
- ../tests/roles/confd/main.yml | ||
- ../tests/roles/deploy-finish/main.yml | ||
- ../tests/roles/haproxy/main.yml | ||
- ../tests/roles/patroni/main.yml | ||
- ../tests/roles/pre-checks/main.yml | ||
- ../tests/roles/swap/main.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
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,13 @@ | ||
--- | ||
# 🚀 This task is designed to include variable tests for the main role in the Confd molecule tests | ||
# 🎯 The goal is to ensure that all variable tests are executed in a systematic and organised manner | ||
|
||
# 🔄 Including variable tests for the main role in the Confd molecule tests | ||
# We use a loop to include all YAML files in the 'variables' directory | ||
# Each file is included as a task, ensuring that all variable tests are executed | ||
- name: Molecule.tests.roles.confd.main | Include Variable Tests | ||
run_once: true | ||
ansible.builtin.include_tasks: "{{ molecule_tests_roles_confd_main_file }}" | ||
loop: "{{ lookup('fileglob', 'variables/*.yml', wantlist=True) }}" | ||
loop_control: | ||
loop_var: molecule_tests_roles_confd_main_file |
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,162 @@ | ||
--- | ||
# 🚀 These tasks aim to test the "ansible.builtin.lineinfile" task | ||
# 🎯 The objective is to ensure that the lines are correctly replaced | ||
|
||
# 📂 Ensure tmp directory exists | ||
- name: Molecule.tests.roles.confd.variables.haproxy.tmpl | Ensure tmp directory exists | ||
run_once: true | ||
delegate_to: localhost | ||
ansible.builtin.file: | ||
path: "./tmp" | ||
state: directory | ||
|
||
# 🔄 Define a dummy template file | ||
- name: Molecule.tests.roles.confd.variables.haproxy.tmpl | Set template file test data | ||
ansible.builtin.set_fact: | ||
haproxy_listen_port: | ||
master: 5000 | ||
replicas: 5001 | ||
replicas_sync: 5002 | ||
replicas_async: 5003 | ||
stats: 7000 | ||
inventory_hostname: una.name | ||
cluster_vip: fake.vip.url.com | ||
|
||
# =============================== | ||
# 💻 Case cluster_vip is defined | ||
# =============================== | ||
|
||
# 📝 Establishing test data for haproxy.cluster_vip.defined.tmpl | ||
- name: Molecule.tests.roles.confd.variables.haproxy.tmpl | Establish haproxy.tmpl Test Data | ||
run_once: true | ||
delegate_to: localhost | ||
ansible.builtin.copy: | ||
dest: "./tmp/haproxy.cluster_vip.defined.tmpl" | ||
content: | | ||
bind *:{{ haproxy_listen_port.stats }} | ||
bind *:{{ haproxy_listen_port.master }} | ||
bind *:{{ haproxy_listen_port.replicas }} | ||
bind *:{{ haproxy_listen_port.replicas_sync }} | ||
bind *:{{ haproxy_listen_port.replicas_async }} | ||
# 🚀 Execute the main task here | ||
# This task updates the 'haproxy.tmpl' file | ||
# replacing lines that start with 'bind' and include specific ports | ||
# The new lines will either bind to the inventory_hostname or the cluster_vip, depending on the specific port. | ||
- name: Molecule.tests.roles.confd.variables.haproxy.tmpl | Update haproxy.tmpl (replace "bind") | ||
run_once: true | ||
delegate_to: localhost | ||
ansible.builtin.lineinfile: | ||
path: ./tmp/haproxy.cluster_vip.defined.tmpl | ||
regexp: "{{ bind_config_with_vip_item.regexp }}" | ||
line: "{{ bind_config_with_vip_item.line }}" | ||
backrefs: true | ||
loop: | ||
- regexp: '^.*bind.*:{{ haproxy_listen_port.stats }}$' | ||
line: ' bind {{ inventory_hostname }}:{{ haproxy_listen_port.stats }}' | ||
- regexp: '^.*bind.*:{{ haproxy_listen_port.master }}$' | ||
line: ' bind {{ cluster_vip }}:{{ haproxy_listen_port.master }}' | ||
- regexp: '^.*bind.*:{{ haproxy_listen_port.replicas }}$' | ||
line: ' bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas }}' | ||
- regexp: '^.*bind.*:{{ haproxy_listen_port.replicas_sync }}$' | ||
line: ' bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync }}' | ||
- regexp: '^.*bind.*:{{ haproxy_listen_port.replicas_async }}$' | ||
line: ' bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async }}' | ||
loop_control: | ||
loop_var: bind_config_with_vip_item | ||
label: "{{ bind_config_with_vip_item.line }}" | ||
|
||
# 🖨️ Debugging the established haproxy.tmpl | ||
- name: Molecule.tests.roles.confd.variables.haproxy.tmpl | Debug haproxy.tmpl | ||
run_once: true | ||
delegate_to: localhost | ||
ansible.builtin.command: | ||
cmd: cat ./tmp/haproxy.cluster_vip.defined.tmpl | ||
register: output | ||
- name: Molecule.tests.roles.confd.variables.haproxy.tmpl | Debug haproxy.tmpl content | ||
run_once: true | ||
ansible.builtin.debug: | ||
var: output.stdout_lines | ||
|
||
# ✅ Verifying the correctness of the established haproxy.tmpl | ||
# If the lines are not replaced correctly, the test fails and an error message is displayed | ||
- name: Molecule.tests.roles.confd.variables.haproxy.tmpl | Validate updated haproxy.tmpl | ||
run_once: true | ||
ansible.builtin.assert: | ||
that: | ||
- "output.stdout_lines[0] == ' bind una.name:7000'" | ||
- "output.stdout_lines[1] == ' bind fake.vip.url.com:5000'" | ||
- "output.stdout_lines[2] == ' bind fake.vip.url.com:5001'" | ||
- "output.stdout_lines[3] == ' bind fake.vip.url.com:5002'" | ||
- "output.stdout_lines[4] == ' bind fake.vip.url.com:5003'" | ||
fail_msg: "Test failed: Lines are not replaced correctly in haproxy.tmpl." | ||
success_msg: "Test passed: Lines are replaced correctly in haproxy.tmpl." | ||
|
||
# =================================== | ||
# 💻 Case cluster_vip is not defined | ||
# =================================== | ||
|
||
# 📝 Establishing test data for haproxy.cluster_vip.not.defined.tmpl | ||
- name: Molecule.tests.roles.confd.variables.haproxy.tmpl | Establish haproxy.tmpl Test Data - 2nd round | ||
run_once: true | ||
delegate_to: localhost | ||
ansible.builtin.copy: | ||
dest: "./tmp/haproxy.cluster_vip.not.defined.tmpl" | ||
content: | | ||
bind *:{{ haproxy_listen_port.stats }} | ||
bind *:{{ haproxy_listen_port.master }} | ||
bind *:{{ haproxy_listen_port.replicas }} | ||
bind *:{{ haproxy_listen_port.replicas_sync }} | ||
bind *:{{ haproxy_listen_port.replicas_async }} | ||
# 🚀 Execute the new task here | ||
# This task updates the 'haproxy.tmpl' file again, this time replacing lines that start with 'bind' and include specific ports | ||
# The new lines will bind to the inventory_hostname. | ||
- name: Molecule.tests.roles.confd.variables.haproxy.tmpl | Prepare haproxy.tmpl template file (replace "bind" - 2nd round) | ||
run_once: true | ||
delegate_to: localhost | ||
ansible.builtin.lineinfile: | ||
path: ./tmp/haproxy.cluster_vip.not.defined.tmpl | ||
regexp: "{{ bind_config_without_vip_item.regexp }}" | ||
line: "{{ bind_config_without_vip_item.line }}" | ||
backrefs: true | ||
loop: | ||
- regexp: '^.*bind.*:{{ haproxy_listen_port.stats }}$' | ||
line: ' bind {{ inventory_hostname }}:{{ haproxy_listen_port.stats }}' | ||
- regexp: '^.*bind.*:{{ haproxy_listen_port.master }}$' | ||
line: ' bind {{ inventory_hostname }}:{{ haproxy_listen_port.master }}' | ||
- regexp: '^.*bind.*:{{ haproxy_listen_port.replicas }}$' | ||
line: ' bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas }}' | ||
- regexp: '^.*bind.*:{{ haproxy_listen_port.replicas_sync }}$' | ||
line: ' bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_sync }}' | ||
- regexp: '^.*bind.*:{{ haproxy_listen_port.replicas_async }}$' | ||
line: ' bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_async }}' | ||
loop_control: | ||
loop_var: bind_config_without_vip_item | ||
label: "{{ bind_config_without_vip_item.line }}" | ||
|
||
# 🖨️ Debugging the established haproxy.tmpl - 2nd round | ||
- name: Molecule.tests.roles.confd.variables.haproxy.tmpl | Debug haproxy.tmpl - 2nd round | ||
run_once: true | ||
delegate_to: localhost | ||
ansible.builtin.command: | ||
cmd: cat ./tmp/haproxy.cluster_vip.not.defined.tmpl | ||
register: output_2 | ||
- name: Molecule.tests.roles.confd.variables.haproxy.tmpl | Debug haproxy.tmpl content - 2nd round | ||
run_once: true | ||
ansible.builtin.debug: | ||
var: output_2.stdout_lines | ||
|
||
# ✅ Verifying the correctness of the established haproxy.tmpl - 2nd round | ||
# If the lines are not replaced correctly, the test fails and an error message is displayed | ||
- name: Molecule.tests.roles.confd.variables.haproxy.tmpl | Verify haproxy.tmpl - 2nd round | ||
run_once: true | ||
ansible.builtin.assert: | ||
that: | ||
- "output_2.stdout_lines[0] == ' bind una.name:7000'" | ||
- "output_2.stdout_lines[1] == ' bind una.name:5000'" | ||
- "output_2.stdout_lines[2] == ' bind una.name:5001'" | ||
- "output_2.stdout_lines[3] == ' bind una.name:5002'" | ||
- "output_2.stdout_lines[4] == ' bind una.name:5003'" | ||
fail_msg: "Test failed: Lines are not replaced correctly in haproxy.tmpl - 2nd round." | ||
success_msg: "Test passed: Lines are replaced correctly in haproxy.tmpl - 2nd round." |
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,13 @@ | ||
--- | ||
# 🚀 This task is designed to include and execute a series of variable tests for the 'deploy-finish' role in our Molecule test suite. | ||
# 🎯 The objective is to ensure that all variable tests are run in a systematic and efficient manner, thus ensuring the integrity of our deployment process. | ||
|
||
# 🔄 Including and executing variable tests for the 'deploy-finish' role | ||
# We use a loop to iterate over all the YAML files in the 'variables' directory, and for each file, we include its tasks in the current playbook. | ||
# This allows us to run a comprehensive set of variable tests in an automated and efficient manner. | ||
- name: Molecule.tests.roles.deploy-finish.main | Include and Execute Variable Tests | ||
run_once: true | ||
ansible.builtin.include_tasks: "{{ molecule_tests_roles_deploy_finish_main_file }}" | ||
loop: "{{ lookup('fileglob', 'variables/*.yml', wantlist=True) }}" | ||
loop_control: | ||
loop_var: molecule_tests_roles_deploy_finish_main_file |
71 changes: 71 additions & 0 deletions
71
molecule/tests/roles/deploy-finish/variables/haproxy_nodes.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,71 @@ | ||
--- | ||
# 🚀 These tasks aim to test the haproxy_nodes variable | ||
# 🎯 The objective is to guarantee that the list of nodes is correctly set | ||
|
||
# ============================================ | ||
# 💻 Start haproxy_nodes Operations and Tests | ||
# ============================================ | ||
|
||
# 📝 Establishing test data for haproxy_nodes | ||
- name: Molecule.tests.rolesdeploy-finish.variables.haproxy_nodes | Establish haproxy_nodes Test Data | ||
run_once: true | ||
ansible.builtin.set_fact: | ||
haproxy_nodes: >- | ||
{{ | ||
groups['balancers'] | ||
| default([]) | ||
| map('extract', hostvars, 'inventory_hostname') | ||
| join(',') | ||
}} | ||
# 🖨️ Debugging the established haproxy_nodes | ||
- name: Molecule.tests.rolesdeploy-finish.variables.haproxy_nodes | Debug haproxy_nodes | ||
run_once: true | ||
ansible.builtin.debug: | ||
var: haproxy_nodes | ||
|
||
# ✅ Verifying the correctness of the established haproxy_nodes | ||
# If the haproxy_nodes is not set, the test fails and an error message is displayed | ||
- name: Molecule.tests.rolesdeploy-finish.variables.haproxy_nodes | Verify haproxy_nodes | ||
run_once: true | ||
ansible.builtin.assert: | ||
that: | ||
- "haproxy_nodes is not none" | ||
- "haproxy_nodes != 'N/A'" | ||
- "haproxy_nodes == 'una.name,10.172.0.21,10.172.0.22'" | ||
fail_msg: "Test failed: haproxy_nodes is not set correctly." | ||
success_msg: "Test passed: haproxy_nodes is set correctly." | ||
|
||
# ===================================================== | ||
# 💻 Start postgres_cluster_nodes Operations and Tests | ||
# ===================================================== | ||
|
||
# 📝 Establishing test data for postgres_cluster_nodes | ||
- name: Molecule.tests.rolesdeploy-finish.variables.haproxy_nodes | Establish postgres_cluster_nodes Test Data | ||
run_once: true | ||
ansible.builtin.set_fact: | ||
postgres_cluster_nodes: >- | ||
{{ | ||
groups['postgres_cluster'] | ||
| default([]) | ||
| map('extract', hostvars, 'inventory_hostname') | ||
| join(',') | ||
}} | ||
# 🖨️ Debugging the established postgres_cluster_nodes | ||
- name: Molecule.tests.rolesdeploy-finish.variables.haproxy_nodes | Debug postgres_cluster_nodes | ||
run_once: true | ||
ansible.builtin.debug: | ||
var: postgres_cluster_nodes | ||
|
||
# ✅ Verifying the correctness of the established postgres_cluster_nodes | ||
# If the postgres_cluster_nodes is not set, the test fails and an error message is displayed | ||
- name: Molecule.tests.rolesdeploy-finish.variables.haproxy_nodes | Verify postgres_cluster_nodes | ||
run_once: true | ||
ansible.builtin.assert: | ||
that: | ||
- "postgres_cluster_nodes is not none" | ||
- "postgres_cluster_nodes != 'N/A'" | ||
- "postgres_cluster_nodes == 'una.name,10.172.0.21,10.172.0.22'" | ||
fail_msg: "Test failed: postgres_cluster_nodes is not set correctly." | ||
success_msg: "Test passed: postgres_cluster_nodes is set correctly." |
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,13 @@ | ||
--- | ||
# 🚀 The purpose of this task is to incorporate a series of variable tests for HAProxy, a reliable, high performance TCP/HTTP load balancer | ||
# 🎯 The objective is to ensure that the variables used in the HAProxy configuration are correctly defined and functional | ||
|
||
# 🔄 Including variable tests for HAProxy | ||
# This task iterates over all the YAML files in the 'variables' directory, and includes each file's tasks in the current playbook | ||
# If a variable test fails, it will be immediately apparent, aiding in debugging and ensuring the robustness of the HAProxy configuration | ||
- name: Molecule.tests.roles.haproxy.main | Incorporate Variable Tests | ||
run_once: true | ||
ansible.builtin.include_tasks: "{{ molecule_tests_roles_haproxy_main_file }}" | ||
loop: "{{ lookup('fileglob', 'variables/*.yml', wantlist=True) }}" | ||
loop_control: | ||
loop_var: molecule_tests_roles_haproxy_main_file |
Oops, something went wrong.