The Ansible role sap_maintain_etc_hosts is used to maintain the /etc/hosts file..
- Assert that required inputs were provided.
- Verify duplicate entries and conflicts;
- Update
/etc/hostsfile.
Example playbook will update /etc/hosts:
- Remove node with IP
10.10.10.10. - Remove node with name
host2. - Add node with IP
10.10.10.11, namehost1, aliasesalias1, alias2and commenthost1 comment.
- name: Ansible Play for add entry in /etc/hosts
hosts: all
become: true
tasks:
- name: Execute Ansible Role sap_sap_maintain_etc_hosts
ansible.builtin.include_role:
name: community.sap_install.sap_sap_maintain_etc_hosts
vars:
sap_maintain_etc_hosts_list:
- node_ip: 10.10.10.10
state: absent
- node_name: host2
state: absent
- node_ip: 10.10.10.11
node_name: host1
aliases:
- alias1
- alias2
node_comment: "host1 comment" # Comment is created after hash sign (defaults to hana_site)
state: presentExample playbook when executed together with sap_ha_pacemaker_cluster role which uses either sap_ha_pacemaker_cluster_cluster_nodes or sap_hana_cluster_nodes.
- name: Ansible Play for add entry in /etc/hosts
hosts: all
become: true
tasks:
- name: Execute Ansible Role sap_sap_maintain_etc_hosts
ansible.builtin.include_role:
name: community.sap_install.sap_sap_maintain_etc_hosts
vars:
sap_maintain_etc_hosts_list: "{{ sap_ha_pacemaker_cluster_cluster_nodes }}"For more examples on how to use this role in different installation scenarios, refer to the ansible.playbooks_for_sap playbooks.
Apache 2.0
This role requires the dictionary sap_maintain_etc_hosts_list which contains the parameters for the /etc/hosts file.
The default value is the definition of the cluster nodes like in the role sap_ha_pacemaker_cluster.
If the value sap_hana_cluster_nodesor sap_ha_pacemaker_cluster_cluster_nodes is not defined, then the role creates a default value from ansible_facts.
NOTE: If you want to use this role to remove entries from /etc/hosts it is a good practice to do this before adding entries. The adding/removal is done in the order the entries are listed.
- Type:
listwith elements of typedict
Mandatory list of nodes in form of dictionaries to be added or removed in /etc/hosts file.
Following dictionary keys can be defined:
-
node_ip
IP address of the managed node.
Required for adding new entries to/etc/hosts.
Optional for removing entries, wherenode_nameandnode_domaincan be used instead.- Type:
string
- Type:
-
node_name
Hostname of the managed node.
Required for adding new entries to/etc/hosts.
Optional for removing entries, whennode_ipis not used.- Type:
string
- Type:
-
node_domain
Domain name of the managed node. Defaults tosap_domainif set oransible_facts['domain'].
Required for adding new entries to/etc/hosts.
Optional for removing entries, whennode_nameis used.- Type:
string - Default:
sap_domain
- Type:
-
aliases
List of aliases for the managed node.
Optional for adding new entries to/etc/hosts.- Type:
listwith elements of typestring
- Type:
-
alias_mode
Select method of updating/etc/hostsfile:
-merge: merges the list of aliases with the exiting aliases of the node.
-overwrite: overwrites the aliases of the node. Optional for adding new entries to/etc/hosts.- Type:
string - Default:
merge
- Type:
-
node_comment
Node comment is appended at end of line of managed node.
Optional for adding new entries to/etc/hosts.- Type:
string - Default:
managed by ansible sap_maintain_etc_hosts role
- Type:
-
hana_site
Used by sap_ha_pacemaker_cluster and it is appended tonode_comment
Optional for adding new entries to/etc/hosts.- Type:
string
- Type:
-
node_role
Not used, but mentioned for compatibility reasons for sap_ha_pacemaker_cluster role.- Type:
string
- Type:
-
state
Selectpresentfor adding new entries,absentfor removing them.
Required for removing entries, otherwise defaultpresentis used.- Type:
string - Default:
present
- Type: