Skip to content

Commit

Permalink
add missing condition to ensure a failed unit only has its failed sta…
Browse files Browse the repository at this point in the history
…te reset if it actually is in a failed state
  • Loading branch information
andanotheruser committed Nov 14, 2024
1 parent 326be54 commit 708a9f5
Show file tree
Hide file tree
Showing 12 changed files with 277 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tasks/manage_node_state.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
become: true
when: inventory_hostname == item

- name: manage_node_state | Populate service facts
ansible.builtin.service_facts:

- name: manage_node_state | reset failed status (otherwise service can't be stopped)
command: "systemctl reset-failed {{ mariadb_systemd_service_name }}" # noqa command-instead-of-module
become: true
check_mode: false
changed_when: false
ignore_errors: true
when:
- '"stopped" in mariadb_systemd_service_state'
- '"failed" in ansible_facts.services[mariadb_systemd_service_name].state'
- inventory_hostname == item

- name: manage_node_state | ensure node is fully stopped before continuing
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup_cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
galera_extra_wsrep_provider_options: >
{{
galera_extra_wsrep_provider_options | combine({
'ist.recv_addr': galera_ist_recv_addr + ":" + galera_ist_recv_addr_port,
'ist.recv_addr': galera_ist_recv_addr + ":" + galera_ist_recv_addr_port|string,
'ist.recv_bind': galera_ist_recv_bind
})
}}
Expand Down
2 changes: 2 additions & 0 deletions tests/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[defaults]
inventory = ./inventory
58 changes: 58 additions & 0 deletions tests/create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---

- name: Creating Galera Test Scenario
hosts: localhost
vars:
openstack_cloud: testing
openstack_ssh_key: testing
openstack_flavor_name: gp1a.4
openstack_image_name_deb12: debian-12-generic-amd64
openstack_image_name_deb11: debian-11-generic-amd64
openstack_network_name: network-k0stesting_generic
tasks:
- name: Include variables
ansible.builtin.include_vars: "vars/main.yml"

- name: Fetch Image (Deb12)

Check failure on line 16 in tests/create.yml

View workflow job for this annotation

GitHub Actions / pre-commit Lint

syntax-check[specific]

couldn't resolve module/action 'openstack.cloud.image_info'. This often indicates a misspelling, missing collection, or incorrect module path.
openstack.cloud.image_info:
cloud: "{{ openstack_cloud }}"
image: "{{ openstack_image_name_deb12 }}"
register: _openstack_image_deb12

- name: Fetch Flavor
openstack.cloud.compute_flavor_info:
cloud: "{{ openstack_cloud }}"
name: "{{ openstack_flavor_name }}"
register: _openstack_flavor

- name: Fetch Network
openstack.cloud.networks_info:
cloud: "{{ openstack_cloud }}"
name: "{{ openstack_network_name }}"
register: _openstack_network

- name: Ensure SSH Key exists
openstack.cloud.keypair:
name: "{{ openstack_ssh_key }}"
cloud: "{{ openstack_cloud }}"
public_key_file: "{{ ansible_env.HOME }}/.ssh/testing.pub"

- name: Create Galera Instances
openstack.cloud.server:
name: "{{ item }}"
state: present
image: "{{ _openstack_image_deb12.images[0].id }}"
key_name: "{{ openstack_ssh_key }}"
flavor: "{{ _openstack_flavor.flavors[0].id }}"
network: "{{ _openstack_network.networks[0].id }}"
terminate_volume: true
security_groups:
- 1aa4fd40-1650-4151-84a7-3f5ecc4c4b23
cloud: "{{ openstack_cloud }}"
metadata:
group: "{{ the_role_name }}"
auto_ip: false
loop:
- galera-1
- galera-2
- galera-3
17 changes: 17 additions & 0 deletions tests/destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---

- name: Destroying Test Scenario
hosts: localhost
vars:
openstack_cloud: testing
tasks:

- name: Destroy Instances

Check failure on line 9 in tests/destroy.yml

View workflow job for this annotation

GitHub Actions / pre-commit Lint

syntax-check[specific]

couldn't resolve module/action 'openstack.cloud.server'. This often indicates a misspelling, missing collection, or incorrect module path.
openstack.cloud.server:
state: absent
name: "{{ item }}"
cloud: "{{ openstack_cloud }}"
loop:
- galera-1
- galera-2
- galera-3
12 changes: 12 additions & 0 deletions tests/inventory/openstack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
plugin: openstack.cloud.openstack
expand_hostvars: true
private: true
legacy_groups: false
keyed_groups:
- key: openstack.metadata.group
default_value: galera
parent_group: all
leading_separator: false
only_clouds:
- testing
63 changes: 63 additions & 0 deletions tests/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---

- name: Creating Test Environment for Galera
hosts: mariadb_galera_cluster
order: sorted
pre_tasks:
- name: Set hostname
ansible.builtin.hostname:
name: "{{ inventory_hostname }}"
become: true
- name: Reload facts
ansible.builtin.setup:
- name: Refresh Inventory
ansible.builtin.meta: refresh_inventory
- name: Set Hostnames
ansible.builtin.lineinfile:
path: /etc/hosts
line: "{{ hostvars[item].ansible_facts.default_ipv4.address }} {{ hostvars[item].ansible_facts.fqdn }}"
become: true
loop: "{{ ansible_play_hosts }}"
- name: Set Hostnames IPv6
ansible.builtin.lineinfile:
path: /etc/hosts
line: "{{ hostvars[item].ansible_facts.default_ipv6.address }} {{ hostvars[item].ansible_facts.fqdn }}"
become: true
loop: "{{ ansible_play_hosts }}"
- name: Include variables
ansible.builtin.include_vars: "vars/main.yml"
- name: Load mysqld_exporter vars
ansible.builtin.include_vars:
file: mysqld_exporter.yml
roles:
- role: adit.mariadb_galera_cluster

Check failure on line 33 in tests/playbook.yml

View workflow job for this annotation

GitHub Actions / pre-commit Lint

syntax-check[specific]

the role 'adit.mariadb_galera_cluster' was not found in /home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests/roles:/home/runner/.cache/ansible-compat/c01d4a/roles:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests

Check failure on line 33 in tests/playbook.yml

View workflow job for this annotation

GitHub Actions / Molecule Test (debian10, 3.10)

syntax-check[specific]

the role 'adit.mariadb_galera_cluster' was not found in /home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests/roles:/home/runner/.cache/ansible-compat/c01d4a/roles:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests

Check failure on line 33 in tests/playbook.yml

View workflow job for this annotation

GitHub Actions / Molecule Test (debian11, 3.10)

syntax-check[specific]

the role 'adit.mariadb_galera_cluster' was not found in /home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests/roles:/home/runner/.cache/ansible-compat/c01d4a/roles:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests

Check failure on line 33 in tests/playbook.yml

View workflow job for this annotation

GitHub Actions / Molecule Test (debian12, 3.10)

syntax-check[specific]

the role 'adit.mariadb_galera_cluster' was not found in /home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests/roles:/home/runner/.cache/ansible-compat/c01d4a/roles:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests

Check failure on line 33 in tests/playbook.yml

View workflow job for this annotation

GitHub Actions / Molecule Test (rocky8, 3.10)

syntax-check[specific]

the role 'adit.mariadb_galera_cluster' was not found in /home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests/roles:/home/runner/.cache/ansible-compat/c01d4a/roles:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests

Check failure on line 33 in tests/playbook.yml

View workflow job for this annotation

GitHub Actions / Molecule Test (rocky9, 3.10)

syntax-check[specific]

the role 'adit.mariadb_galera_cluster' was not found in /home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests/roles:/home/runner/.cache/ansible-compat/c01d4a/roles:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests

Check failure on line 33 in tests/playbook.yml

View workflow job for this annotation

GitHub Actions / Molecule Test (ubuntu1804, 3.10)

syntax-check[specific]

the role 'adit.mariadb_galera_cluster' was not found in /home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests/roles:/home/runner/.cache/ansible-compat/c01d4a/roles:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests

Check failure on line 33 in tests/playbook.yml

View workflow job for this annotation

GitHub Actions / Molecule Test (ubuntu2004, 3.10)

syntax-check[specific]

the role 'adit.mariadb_galera_cluster' was not found in /home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests/roles:/home/runner/.cache/ansible-compat/c01d4a/roles:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests

Check failure on line 33 in tests/playbook.yml

View workflow job for this annotation

GitHub Actions / Molecule Test (ubuntu2204, 3.10)

syntax-check[specific]

the role 'adit.mariadb_galera_cluster' was not found in /home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests/roles:/home/runner/.cache/ansible-compat/c01d4a/roles:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/runner/work/ansible-mariadb-galera-cluster/ansible-mariadb-galera-cluster/tests
tags:
- mariadb_galera_cluster

- name: MySQL Clustercheck
hosts: mariadb_galera_cluster
order: sorted
pre_tasks:
- name: Include variables
ansible.builtin.include_vars: "vars/main.yml"
- name: Load mysqld_exporter vars
ansible.builtin.include_vars:
file: mysqld_exporter.yml
roles:
- role: adit.mysql_clustercheck
tags:
- mysql_clustercheck

- name: MySQL Clustercheck
hosts: mariadb_galera_cluster
order: sorted
pre_tasks:
- name: Include variables
ansible.builtin.include_vars: "vars/main.yml"
- name: Load mysqld_exporter vars
ansible.builtin.include_vars:
file: mysqld_exporter.yml
roles:
- role: prometheus.prometheus.mysqld_exporter
tags:
- prometheus_mysqld_exporter
80 changes: 80 additions & 0 deletions tests/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---

- name: Linking role
hosts: localhost
vars:
requirements_yml_file: '../requirements.yml'
test_requirements_yml_file: './test_requirements.yml'
tasks:
- name: Include variables
ansible.builtin.include_vars: "vars/main.yml"

- name: Removing existing link
ansible.builtin.file:
path: '~/.ansible/roles/adit.{{ the_role_name }}'
state: absent
- name: Linking role
ansible.builtin.file:
state: link
path: '~/.ansible/roles/adit.{{ the_role_name }}'
src: "{{ playbook_dir }}/.."
- name: Check if requirements_yml_file exists
ansible.builtin.stat:
path: "{{ requirements_yml_file }}"
register: requirements_yml

- name: Include requirements_yml_file as variables
ansible.builtin.include_vars: "{{ requirements_yml_file }}"
when:
- requirements_yml.stat.exists

- name: Remove roles
ansible.builtin.file:
path: "~/.ansible/roles/{{ item.name }}"
state: absent
with_items:
- "{{ roles }}"
when:
- roles is defined

- name: Install roles
ansible.builtin.command:
cmd: "ansible-galaxy install -r {{ requirements_yml_file }}"
register: ansible_galaxy_output
with_items:
- "{{ roles }}"
when:
- roles is defined
changed_when: ansible_galaxy_output.rc != 0

######################### Role-Requirements for test-Playbooks
- name: Check if test_requirements_yml_file exists
ansible.builtin.stat:
path: "{{ test_requirements_yml_file }}"
register: test_requirements_yml

- name: "Install required roles for test-environment"
when:
- test_requirements_yml.stat.exists
block:
- name: Include test_requirements_yml_file as variables
ansible.builtin.include_vars: "{{ test_requirements_yml_file }}"

- name: Remove roles
ansible.builtin.file:
path: "~/.ansible/roles/{{ item.name }}"
state: absent
with_items:
- "{{ roles }}"
when:
- roles is defined

- name: Install roles
ansible.builtin.command:
cmd: "ansible-galaxy install -r {{ test_requirements_yml_file }}"
register: ansible_galaxy_output
with_items:
- "{{ roles }}"
when:
- roles is defined
changed_when: ansible_galaxy_output.rc != 0
11 changes: 11 additions & 0 deletions tests/test_requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
roles:
- name: adit.mysql_clustercheck
src: https://group_549_bot_5c252634c40b20e971f823cea50a2254:[email protected]/adit/infrastructure/ansible/mysql_clustercheck.git
scm: git
version: 0.1.1
collections:
- name: community.docker
version: "*" # Need to ensure that the latest version is installed or Molecule fails
- name: prometheus.prometheus
version: 0.17.0
10 changes: 10 additions & 0 deletions tests/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

- name: Test stuff
hosts: mariadb_galera_cluster
tags:
- testing
tasks:
- name: Print ssh command
ansible.builtin.debug:
msg: 'ssh {{ ansible_default_ipv4.address }}'
13 changes: 13 additions & 0 deletions tests/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# tests/vars/main.yml
# defintion of needed variables
---

db_path: "{{ kv_path }}/database"
galera_cluster_bind_interface: '{{ ansible_default_ipv4.interface }}'
galera_cluster_name: "testcluster"
galera_cluster_nodes_group: "{{ the_role_name }}"
galera_mysql_first_node: "{{ groups[the_role_name][0] }}"
kv_path: "/customer/{{ customer }}/mariadb"
mariadb_debian_repo_key_url: "https://mariadb.org/mariadb_release_signing_key.asc"
the_role_name: 'mariadb_galera_cluster'
user_path: "{{ kv_path }}/user"
5 changes: 5 additions & 0 deletions tests/vars/mysqld_exporter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

# MySQLd Exporter Vars
mysqld_exporter_username: "test"
mysqld_exporter_password: "test"

0 comments on commit 708a9f5

Please sign in to comment.