Skip to content

Commit

Permalink
chore(ansible-lint.yml): remove yaml[line-length] from skip_list (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasSanson authored Jul 17, 2023
1 parent 48f019d commit 63e981d
Show file tree
Hide file tree
Showing 38 changed files with 1,560 additions and 86 deletions.
3 changes: 2 additions & 1 deletion .config/.yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
extends: default

rules:
line-length: disable
line-length:
max: 160
comments-indentation: disable
comments:
min-spaces-from-content: 1
Expand Down
1 change: 0 additions & 1 deletion .config/ansible-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ skip_list:
- package-latest
- risky-file-permissions # TODO
- role-name
- yaml[line-length]

exclude_paths:
- ../.venv
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
.idea
.venv
.vscode/settings.json
__pycache__/
__pycache__/
*.log
molecule/**/tmp
15 changes: 13 additions & 2 deletions deploy_pgcluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,20 @@
system_info:
OS: "{{ ansible_distribution | default('N/A') }} {{ ansible_distribution_version | default('N/A') }}"
Kernel: "{{ ansible_kernel | default('N/A') }}"
CPU model: "{{ ansible_processor[2] | default('N/A') }}, count: {{ ansible_processor_count | default('N/A') }}, cores: {{ ansible_processor_cores | default('N/A') }}"
CPU model: >-
{{ ansible_processor[2] | default('N/A') }},
count: {{ ansible_processor_count | default('N/A') }},
cores: {{ ansible_processor_cores | default('N/A') }}
Memory: "{{ (ansible_memtotal_mb / 1024) | round(2) if ansible_memtotal_mb is defined else 'N/A' }} GB"
Disk space total: "{{ (ansible_mounts | map(attribute='size_total') | map('int') | sum / 1024 / 1024 / 1024) | round(2) if ansible_mounts is defined else 'N/A' }} GB"
Disk space total: >-
{{
(ansible_mounts
| map(attribute='size_total')
| map('int')
| sum / 1024 / 1024 / 1024
)
| round(2) if ansible_mounts is defined else 'N/A'
}} GB
Architecture: "{{ ansible_architecture | default('N/A') }}"
Virtualization type: "{{ ansible_virtualization_type | default('N/A') }}"
Product name: "{{ ansible_product_name | default('N/A') }}"
Expand Down
27 changes: 24 additions & 3 deletions molecule/default/verify.yml
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
7 changes: 5 additions & 2 deletions molecule/postgrespro/vars/postgrespro_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ postgresql_bin_dir: "/opt/pgpro/std-{{ postgresql_version }}/bin"
postgresql_unix_socket_dir: "/tmp"

# YUM Repository
_baseurl:
_baseurl: # yamllint disable rule:line-length
CentOS: "https://repo.postgrespro.ru//pgpro-archive/pgpro-{{ postgrespro_minor_version }}/centos/{{ ansible_distribution_major_version }}/os/x86_64/rpms/"
RedHat: "https://repo.postgrespro.ru//pgpro-archive/pgpro-{{ postgrespro_minor_version }}/rhel/{{ ansible_distribution_major_version }}Server/os/x86_64/rpms/"
OracleLinux: "https://repo.postgrespro.ru//pgpro-archive/pgpro-{{ postgrespro_minor_version }}/oraclelinux/{{ ansible_distribution_major_version }}Server/os/x86_64/rpms/"
Expand All @@ -25,7 +25,10 @@ yum_repository:
apt_repository_keys:
- key: "https://repo.postgrespro.ru/keys/GPG-KEY-POSTGRESPRO"
apt_repository:
- repo: "deb https://repo.postgrespro.ru//pgpro-archive/pgpro-{{ postgrespro_minor_version }}/{{ ansible_distribution | lower }}/ {{ ansible_distribution_release }} main"
- repo: >-
{{ 'deb https://repo.postgrespro.ru//pgpro-archive/pgpro-' ~
postgrespro_minor_version ~ '/' ~ (ansible_distribution | lower) ~ '/' ~
' ' ~ ansible_distribution_release ~ ' main' }}
install_postgresql_repo: false

Expand Down
13 changes: 13 additions & 0 deletions molecule/tests/roles/confd/main.yml
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
162 changes: 162 additions & 0 deletions molecule/tests/roles/confd/variables/haproxy.tmpl.yml
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."
13 changes: 13 additions & 0 deletions molecule/tests/roles/deploy-finish/main.yml
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 molecule/tests/roles/deploy-finish/variables/haproxy_nodes.yml
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."
13 changes: 13 additions & 0 deletions molecule/tests/roles/haproxy/main.yml
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
Loading

0 comments on commit 63e981d

Please sign in to comment.