commit b10e9f539263e1a2fd9222d6c52c55c7cb337130 Author: Bernd Finger Date: Wed Oct 2 22:54:14 2019 +0200 - convert variables to bool when comparing in when: statements - always use ansible_hostname + ansible_domain instead of ansible_fqdn diff --git a/tasks/sapnote/2002167/03-setting-the-hostname.yml b/tasks/sapnote/2002167/03-setting-the-hostname.yml index f4e57f8..21de429 100644 --- a/tasks/sapnote/2002167/03-setting-the-hostname.yml +++ b/tasks/sapnote/2002167/03-setting-the-hostname.yml @@ -19,40 +19,40 @@ failed_when: change_hostname.rc >= 2 - name: Check if ipv4 address, FQDN, and hostname are in /etc/hosts - command: bash -lc "awk 'BEGIN{a=0}/{{ ansible_default_ipv4.address }}/&&/{{ ansible_fqdn }}/&&/{{ ansible_hostname }}/{a++}END{print a}' /etc/hosts" + command: bash -lc "awk 'BEGIN{a=0}/{{ ansible_default_ipv4.address }}/&&/{{ ansible_hostname }}.{{ ansible_domain }}/&&/{{ ansible_hostname }}/{a++}END{print a}' /etc/hosts" register: command_result changed_when: no - debug: var: command_result.stdout_lines, command_result.stderr_lines when: - - not sap_preconfigure_modify_etc_hosts + - not sap_preconfigure_modify_etc_hosts | bool - debug: msg: - "Expected:" - - "{{ ansible_default_ipv4.address }} {{ ansible_fqdn }} {{ ansible_hostname }}" + - "{{ ansible_default_ipv4.address }} {{ ansible_hostname }}.{{ ansible_domain }} {{ ansible_hostname }}" when: - command_result.stdout != "1" - - not sap_preconfigure_modify_etc_hosts + - not sap_preconfigure_modify_etc_hosts | bool - fail: msg: - "Server's ipv4 address, FQDN, or hostname are not in /etc/hosts!" when: - command_result.stdout != "1" - - not sap_preconfigure_modify_etc_hosts + - not sap_preconfigure_modify_etc_hosts | bool - name: Make sure server's IP address is in /etc/hosts lineinfile: path: /etc/hosts regexp: '^{{ ansible_default_ipv4.address }}' insertbefore: '^127.0.0.1' -# line: "{{ ansible_default_ipv4.address }} {{ ansible_fqdn }} {{ ansible_hostname }} " - line: "{{ ansible_default_ipv4.address }} {{ ansible_hostname }}.{{ ansible_domain }} {{ ansible_hostname }} " +# line: "{{ ansible_default_ipv4.address }} {{ ansible_fqdn }} {{ ansible_hostname }}" + line: "{{ ansible_default_ipv4.address }} {{ ansible_hostname }}.{{ ansible_domain }} {{ ansible_hostname }}" state: present when: - - sap_preconfigure_modify_etc_hosts + - sap_preconfigure_modify_etc_hosts | bool - debug: - msg: "System {{ ansible_hostname }}, {{ ansible_fqdn }} has ipv4 address {{ ansible_default_ipv4.address }}" + msg: "System {{ ansible_hostname }}, {{ ansible_hostname }}.{{ ansible_domain }} has ipv4 address {{ ansible_default_ipv4.address }}" ... diff --git a/tasks/sapnote/2772999/03-configure-hostname.yml b/tasks/sapnote/2772999/03-configure-hostname.yml index f89ca68..3de61a5 100644 --- a/tasks/sapnote/2772999/03-configure-hostname.yml +++ b/tasks/sapnote/2772999/03-configure-hostname.yml @@ -19,40 +19,40 @@ failed_when: change_hostname.rc >= 2 - name: Check if ipv4 address, FQDN, and hostname are in /etc/hosts - command: bash -lc "awk 'BEGIN{a=0}/{{ ansible_default_ipv4.address }}/&&/{{ ansible_fqdn }}/&&/{{ ansible_hostname }}/{a++}END{print a}' /etc/hosts" + command: bash -lc "awk 'BEGIN{a=0}/{{ ansible_default_ipv4.address }}/&&/{{ ansible_hostname }}.{{ ansible_domain }}/&&/{{ ansible_hostname }}/{a++}END{print a}' /etc/hosts" register: command_result changed_when: no - debug: var: command_result.stdout_lines, command_result.stderr_lines when: - - not sap_preconfigure_modify_etc_hosts + - not sap_preconfigure_modify_etc_hosts | bool - debug: msg: - "Expected:" - - "{{ ansible_default_ipv4.address }} {{ ansible_fqdn }} {{ ansible_hostname }}" + - "{{ ansible_default_ipv4.address }} {{ ansible_hostname }}.{{ ansible_domain }} {{ ansible_hostname }}" when: - command_result.stdout != "1" - - not sap_preconfigure_modify_etc_hosts + - not sap_preconfigure_modify_etc_hosts | bool - fail: msg: - "Server's ipv4 address, FQDN, or hostname are not in /etc/hosts!" when: - command_result.stdout != "1" - - not sap_preconfigure_modify_etc_hosts + - not sap_preconfigure_modify_etc_hosts | bool - name: Make sure server's IP address is in /etc/hosts lineinfile: path: /etc/hosts regexp: '^{{ ansible_default_ipv4.address }}' insertbefore: '^127.0.0.1' -# line: "{{ ansible_default_ipv4.address }} {{ ansible_fqdn }} {{ ansible_hostname }} " - line: "{{ ansible_default_ipv4.address }} {{ ansible_hostname }}.{{ ansible_domain }} {{ ansible_hostname }} " +# line: "{{ ansible_default_ipv4.address }} {{ ansible_fqdn }} {{ ansible_hostname }}" + line: "{{ ansible_default_ipv4.address }} {{ ansible_hostname }}.{{ ansible_domain }} {{ ansible_hostname }}" state: present when: - - sap_preconfigure_modify_etc_hosts + - sap_preconfigure_modify_etc_hosts | bool - debug: - msg: "System {{ ansible_hostname }}, {{ ansible_fqdn }} has ipv4 address {{ ansible_default_ipv4.address }}" + msg: "System {{ ansible_hostname }}, {{ ansible_hostname }}.{{ ansible_domain }} has ipv4 address {{ ansible_default_ipv4.address }}" ...