Skip to content

Commit

Permalink
feat: rsc op defaults for crmsh
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelmamula authored and richm committed Apr 9, 2024
1 parent 0428d3b commit e42be8a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
20 changes: 20 additions & 0 deletions tasks/shell_crmsh/create-and-push-cib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@
properties_set: "{{ ha_cluster_cluster_properties[0] }}"
when: ha_cluster_cluster_properties[0].attrs | d([])

## Resource defaults
- name: Configure resource defaults
ansible.builtin.include_tasks: crm-rsc-op-defaults.yml
vars:
operations: false
loop: "{{ ha_cluster_resource_defaults.meta_attrs | d([]) }}"
loop_control:
index_var: defaults_set_index
loop_var: defaults_set

## Resource operation defaults
- name: Configure resource operation defaults
ansible.builtin.include_tasks: crm-rsc-op-defaults.yml
vars:
operations: true
loop: "{{ ha_cluster_resource_operation_defaults.meta_attrs | d([]) }}"
loop_control:
index_var: defaults_set_index
loop_var: defaults_set

## Resources
- name: Configure cluster resources
ansible.builtin.include_tasks: crm-cib-resource-primitive.yml
Expand Down
2 changes: 1 addition & 1 deletion tasks/shell_crmsh/crm-cib-constraint-order.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Verify if constraint.resource_first.id exists
- name: Verify resource_first presence {{ constraint.resource_first.id }}
ansible.builtin.command:
cmd: |
cmd: >-
crm -c {{ __ha_cluster_crm_shadow }}
configure show {{ constraint.resource_first.id }}
register: __ha_cluster_constraint_resource_first
Expand Down
61 changes: 61 additions & 0 deletions tasks/shell_crmsh/crm-rsc-op-defaults.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# SPDX-License-Identifier: MIT
---
# Verify if defaults_set.id exists
- name: Block for handling defined defaults_set.id
when: defaults_set.id is defined
block:
- name: Verify defaults set presence {{ defaults_set.id | d('') }}
ansible.builtin.command:
cmd: >-
crm -c {{ __ha_cluster_crm_shadow }}
configure show {{ defaults_set.id }}
register: __ha_cluster_defaults_set_status
changed_when: false
failed_when: false

# Delete defaults set in Shadow CIB to avoid errors during cibadmin patch.
- name: Delete present defaults set {{ defaults_set.id | d('') }}
ansible.builtin.command:
cmd: >-
crm --force -c {{ __ha_cluster_crm_shadow }}
configure delete {{ defaults_set.id }}
when:
- __ha_cluster_defaults_set_status.rc == 0
check_mode: false
changed_when: not ansible_check_mode

# TODO: rule and score are not implemented due to cmrsh syntax
- name: Configure rsc/op defaults set {{
defaults_set.id | d(defaults_set_index) }}
ansible.builtin.expect:
command: >
crm -c {{ __ha_cluster_crm_shadow }}
configure
{% if operations %}
op_defaults
{% else %}
rsc_defaults
{% endif %}
{% if defaults_set.id is defined %}
{{ defaults_set.id }}:
{% endif %}
{% if defaults_set.attrs | d([]) %}
{% for attr in defaults_set.attrs %}
{{ attr.name | quote }}={{ attr.value | quote }}
{% endfor %}
{% endif %}
# ERROR and "Do you still want to commit (y/n)?" trigger response "n".
responses:
".*ERROR.*": "n"
".*y/n*": "n"
check_mode: false
changed_when: not ansible_check_mode
ignore_errors: true
register: __ha_cluster_crmsh_output

- name: Display crm command error details
ansible.builtin.fail:
msg: "{{ __ha_cluster_crmsh_output.stdout_lines }}"
when:
- __ha_cluster_crmsh_output is defined
- __ha_cluster_crmsh_output.rc != 0

0 comments on commit e42be8a

Please sign in to comment.