generated from linux-system-roles/template
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for node attributes
- Loading branch information
1 parent
2450454
commit 203212e
Showing
10 changed files
with
282 additions
and
12 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
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,27 @@ | ||
# SPDX-License-Identifier: MIT | ||
--- | ||
- name: Example ha_cluster role invocation - node attributes definition | ||
hosts: all | ||
vars: | ||
ha_cluster_manage_firewall: true | ||
ha_cluster_manage_selinux: true | ||
ha_cluster_cluster_name: my-new-cluster | ||
ha_cluster_hacluster_password: password | ||
ha_cluster_node_options: | ||
- node_name: node1 | ||
attributes: | ||
- attrs: | ||
- name: attribute1 | ||
value: value1A | ||
- name: attribute2 | ||
value: value2A | ||
- node_name: node2 | ||
attributes: | ||
- attrs: | ||
- name: attribute1 | ||
value: value1B | ||
- name: attribute2 | ||
value: value2B | ||
|
||
roles: | ||
- linux-system-roles.ha_cluster |
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,20 @@ | ||
# SPDX-License-Identifier: MIT | ||
--- | ||
- name: Configure node attributes set for node {{ node_options.node_name }} | ||
command: | ||
# Multiple sets of attributes (with rules) per node are not supported by | ||
# pcs (and therefore the role) as of yet | ||
cmd: > | ||
pcs -f {{ __ha_cluster_tempfile_cib_xml.path | quote }} | ||
-- node attribute {{ node_options.node_name | quote }} | ||
{% for attr_set in node_options.attributes | d([], true) %} | ||
{% for attr in attr_set.attrs | d([]) %} | ||
{{ attr.name | quote }}={{ attr.value | quote }} | ||
{% endfor %} | ||
{% endfor %} | ||
# We always need to create CIB to see whether it's the same as what is | ||
# already present in the cluster. However, we don't want to report it as a | ||
# change since the only thing which matters is pushing the resulting CIB to | ||
# the cluster. | ||
check_mode: false | ||
changed_when: not ansible_check_mode |
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,24 @@ | ||
# SPDX-License-Identifier: MIT | ||
--- | ||
- name: Debug ha_cluster_node_options | ||
debug: | ||
var: ha_cluster_node_options | ||
|
||
- name: Run the role and check for errors | ||
block: | ||
- name: Run the role | ||
include_role: | ||
name: linux-system-roles.ha_cluster | ||
|
||
- name: Fail | ||
fail: | ||
msg: Expected failure did not occur | ||
rescue: | ||
- name: Check errors | ||
assert: | ||
that: ansible_failed_result.msg | trim == expected_msg | ||
run_once: true # noqa: run_once[task] | ||
vars: | ||
expected_msg: >- | ||
node_name fields in ha_cluster_node_options | ||
must be unique and they must match cluster nodes |
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,69 @@ | ||
# SPDX-License-Identifier: MIT | ||
--- | ||
- name: Configure node attributes | ||
hosts: all | ||
vars_files: vars/main.yml | ||
|
||
tasks: | ||
- name: Run test | ||
tags: tests::verify | ||
block: | ||
- name: Set up test environment | ||
include_role: | ||
name: linux-system-roles.ha_cluster | ||
tasks_from: test_setup.yml | ||
|
||
- name: Find first node name | ||
set_fact: | ||
__test_first_node: "{{ | ||
(ansible_play_hosts_all | length == 1) | ||
| ternary('localhost', ansible_play_hosts[0]) }}" | ||
|
||
- name: Run HA Cluster role | ||
include_role: | ||
name: linux-system-roles.ha_cluster | ||
public: true | ||
vars: | ||
ha_cluster_cluster_name: test-cluster | ||
ha_cluster_manage_firewall: true | ||
ha_cluster_manage_selinux: true | ||
ha_cluster_node_options: | ||
- node_name: "{{ __test_first_node }}" | ||
attributes: | ||
- attrs: | ||
- name: attr1 | ||
value: val1 | ||
- name: attr2 | ||
value: val2 | ||
- attrs: | ||
- name: attr3 | ||
value: val3 | ||
|
||
- name: Verify node attributes | ||
vars: | ||
__test_expected_lines: | ||
- "Node Attributes:" | ||
- " {{ __test_first_node }}: attr1=val1 attr2=val2 attr3=val3" | ||
block: | ||
- name: Fetch node attributes configuration from the cluster | ||
command: | ||
cmd: pcs node attribute | ||
register: __test_pcs_node_attribute_config | ||
changed_when: false | ||
|
||
- name: Print real node attributes configuration | ||
debug: | ||
var: __test_pcs_node_attribute_config | ||
|
||
- name: Print expected node attributes configuration | ||
debug: | ||
var: __test_expected_lines | list | ||
|
||
- name: Check node attributes configuration | ||
assert: | ||
that: | ||
- __test_pcs_node_attribute_config.stdout_lines | ||
== __test_expected_lines | list | ||
|
||
- name: Check firewall and selinux state | ||
include_tasks: tasks/check_firewall_selinux.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,34 @@ | ||
# SPDX-License-Identifier: MIT | ||
--- | ||
- name: Verify node_name in ha_cluster_node_options check is working | ||
hosts: all | ||
vars_files: vars/main.yml | ||
|
||
tasks: | ||
- name: Run test | ||
tags: tests::verify | ||
block: | ||
- name: Set up test environment | ||
include_role: | ||
name: linux-system-roles.ha_cluster | ||
tasks_from: test_setup.yml | ||
|
||
- name: Find first node name | ||
set_fact: | ||
__test_first_node: "{{ | ||
(ansible_play_hosts_all | length == 1) | ||
| ternary('localhost', ansible_play_hosts[0]) }}" | ||
|
||
- name: Verify node options check is working for various input data | ||
include_tasks: tasks/assert_node_options_check.yml | ||
loop: | ||
# yamllint disable rule:hyphens | ||
- | ||
- node_name: "{{ __test_first_node }}" | ||
- node_name: "{{ __test_first_node }}" | ||
- | ||
- node_name: "{{ __test_first_node }}" | ||
- node_name: "{{ __test_first_node ~ 'x' }}" | ||
# yamllint enable rule:hyphens | ||
loop_control: | ||
loop_var: ha_cluster_node_options |