Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sap_maintain_etc_hosts: no longer use ansible.utils.ip #669

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions roles/sap_maintain_etc_hosts/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@
# the role creates a default value from ansible_facts

sap_maintain_etc_hosts_list: "{{ sap_hana_cluster_nodes | default(sap_ha_pacemaker_cluster_cluster_nodes) | default(omit) }}"

# regex patterns for IP address validation:
sap_maintain_etc_hosts_regexp_ipv4: '^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$'
sap_maintain_etc_hosts_regexp_ipv6: '^(?:[a-fA-F0-9]{0,4}:){7}[a-fA-F0-9]{0,4}$'
12 changes: 12 additions & 0 deletions roles/sap_maintain_etc_hosts/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,15 @@ argument_specs:
state: absent
- node_name: host2
state: absent

sap_maintain_etc_hosts_regexp_ipv4:
default: '^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$'
description:
- regex pattern for IPv4 address validation
type: str

sap_maintain_etc_hosts_regexp_ipv6:
default: '^(?:[a-fA-F0-9]{0,4}:){7}[a-fA-F0-9]{0,4}$'
description:
- regex pattern for IPv6 address validation
type: str
3 changes: 2 additions & 1 deletion roles/sap_maintain_etc_hosts/tasks/update_host_absent.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
- name: Verify that variable node_ip is in the correct format
ansible.builtin.assert:
that: thishost.node_ip is ansible.utils.ip
that: thishost.node_ip | regex_search(sap_maintain_etc_hosts_regexp_ipv4) or
thishost.node_ip | regex_search(sap_maintain_etc_hosts_regexp_ipv6)
msg: "Variable 'node_ip' is not an IP address. Please use the correct format"
when: thisnode.node_ip is defined

Expand Down
3 changes: 2 additions & 1 deletion roles/sap_maintain_etc_hosts/tasks/update_host_present.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

- name: Verify that variable node_ip is in the correct format
ansible.builtin.assert:
that: thishost.node_ip is ansible.utils.ip
that: thishost.node_ip | regex_search(sap_maintain_etc_hosts_regexp_ipv4) or
thishost.node_ip | regex_search(sap_maintain_etc_hosts_regexp_ipv6)
msg: "Variable 'node_ip' is not an IP address. Please use the correct format"

- name: Verify that variable node_name is set
Expand Down
Loading