Skip to content

Commit

Permalink
Merge pull request #981 from berndfinger/issue-132
Browse files Browse the repository at this point in the history
sap_general_preconfigure, sap_maintain_etc_hosts: Ignore comments
  • Loading branch information
berndfinger authored Feb 25, 2025
2 parents 105ef1e + abfa16f commit 2cb168c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
ignore_errors: "{{ sap_general_preconfigure_assert_ignore_errors | d(false) }}"

- name: Check for duplicate or missing entries of {{ sap_general_preconfigure_hostname }}.{{ sap_general_preconfigure_domain }} in /etc/hosts
ansible.builtin.command: awk 'BEGIN{a=0}/^{{ sap_general_preconfigure_hostname }}.{{ sap_general_preconfigure_domain }}\s/||
ansible.builtin.command: awk 'BEGIN{a=0}!/^#/&&(/^{{ sap_general_preconfigure_hostname }}.{{ sap_general_preconfigure_domain }}\s/||
/\s{{ sap_general_preconfigure_hostname }}.{{ sap_general_preconfigure_domain }}\s/||
/\s{{ sap_general_preconfigure_hostname }}.{{ sap_general_preconfigure_domain }}$/{a++}END{print a}' /etc/hosts
/\s{{ sap_general_preconfigure_hostname }}.{{ sap_general_preconfigure_domain }}$/){a++}END{print a}' /etc/hosts
register: __sap_general_preconfigure_register_fqdn_once_assert
ignore_errors: true
changed_when: false
Expand All @@ -51,9 +51,9 @@
ignore_errors: "{{ sap_general_preconfigure_assert_ignore_errors | d(false) }}"

- name: Check for duplicate or missing entries of {{ sap_general_preconfigure_hostname }} in /etc/hosts
ansible.builtin.command: awk 'BEGIN{a=0}/^{{ sap_general_preconfigure_hostname }}\s/||
ansible.builtin.command: awk 'BEGIN{a=0}!/^#/&&(/^{{ sap_general_preconfigure_hostname }}\s/||
/\s{{ sap_general_preconfigure_hostname }}\s/||
/\s{{ sap_general_preconfigure_hostname }}$/{a++}END{print a}' /etc/hosts
/\s{{ sap_general_preconfigure_hostname }}$/){a++}END{print a}' /etc/hosts
register: __sap_general_preconfigure_register_sap_hostname_once_assert
ignore_errors: true
changed_when: false
Expand Down
4 changes: 2 additions & 2 deletions roles/sap_maintain_etc_hosts/tasks/update_host_present.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
# After all nodes are added or deleted, run the consistency check against the hosts file
- name: Check for duplicate or missing entries of hostname and fqdn in {{ __sap_maintain_etc_hosts_file }}
ansible.builtin.shell: |
n=$(awk 'BEGIN{a=0}/^{{ line_item }}\s/||/\s{{ line_item }}\s/||/\s{{ line_item }}$/{a++}END{print a}' {{ __sap_maintain_etc_hosts_file }})
n=$(awk 'BEGIN{a=0}!/^#/&&(/^{{ line_item }}\s/||/\s{{ line_item }}\s/||/\s{{ line_item }}$/){a++}END{print a}' {{ __sap_maintain_etc_hosts_file }})
if [ $n -eq 1 ]; then
exit 0
else
Expand All @@ -169,7 +169,7 @@
when: not ansible_check_mode

- name: Perform the hosts file completeness check
ansible.builtin.command: awk 'BEGIN{a=0}/{{ thishost.node_ip }}/&&/{{ thishost.node_name }}.{{ __sap_maintain_etc_hosts_domain }}/&&/{{ thishost.node_name }}/{a++}END{print a}' {{ __sap_maintain_etc_hosts_file }}
ansible.builtin.command: awk 'BEGIN{a=0}!/^#/&&(/{{ thishost.node_ip }}/&&/{{ thishost.node_name }}.{{ __sap_maintain_etc_hosts_domain }}/&&/{{ thishost.node_name }}/){a++}END{print a}' {{ __sap_maintain_etc_hosts_file }}
register: __sap_maintain_etc_hosts_register_ipv4_fqdn_sap_hostname_once_check
changed_when: false

Expand Down

0 comments on commit 2cb168c

Please sign in to comment.