Skip to content

Commit 32b06cd

Browse files
author
Markus Koch
committed
first fixes implemented
1 parent bd0f4af commit 32b06cd

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

roles/update_etc_hosts/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Role Name
22
=========
33

4-
This role can be used to reliably update teh /etc/hosts file
4+
This role can be used to reliably update the /etc/hosts file
55

66
<!---
77
Requirements
@@ -43,7 +43,7 @@ If you want to setup/add entries your etc hosts you can use this snippet
4343
node_name: host2
4444
state: absent
4545
```
46-
If you have defined a cluster and the variable `sap_ha_pacemaker_cluster_cluster_nodes` or `sap_hana_cluster_nodes` is set, you can use the follwoing play:
46+
If you have defined a cluster and the variable `sap_ha_pacemaker_cluster_cluster_nodes` or `sap_hana_cluster_nodes` is set, you can use the following play:
4747

4848
```[yaml]
4949
- name: ensure all cluster nodes are in /etc/hosts

roles/update_etc_hosts/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
update_etc_hosts_list:
55
- node_ip: "{{ ansible_default_ipv4.address }}"
66
node_name: "{{ ansible_hostname }}"
7+
node_comment: "managed by ansible update_etc_hosts role"
78
state: present

roles/update_etc_hosts/handlers/main.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

roles/update_etc_hosts/meta/argument_specs.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,23 @@ argument_specs:
1616
elements: dict
1717
options:
1818
node_ip:
19+
type: str
1920
description:
2021
- IP address of the node
2122
node_name:
23+
type: str
2224
description:
2325
- Hostname of the node
2426
node_domain:
27+
type: str
2528
description:
2629
- Domainname of the node
27-
- _Optional. Defaults to sap_domain_
30+
- _Optional. Defaults to sap_domain_, if set, then ansible_domain
2831
aliases:
2932
type: list
33+
elements: str
3034
description:
3135
- List of hostname aliases
32-
elements: str
3336
alias_mode:
3437
type: str
3538
default: merge
@@ -39,7 +42,12 @@ argument_specs:
3942
description:
4043
- merges or overwrites the aliases
4144
node_comment:
45+
type: str
46+
default: "managed by ansible update_etc_hosts role"
4247
description: String which is appended to line in hosts after comment string
48+
hana_site:
49+
type: str
50+
description: if set (e.g. for configuring cluster) it is appended to the comment
4351
state:
4452
type: str
4553
default: present

roles/update_etc_hosts/tasks/update_host_present.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929

3030
- name: Set default values
3131
ansible.builtin.set_fact:
32-
__update_etc_hosts_comment: "{{ ( thishost.node_comment|d('') + ' ' + thishost.hana_site|d('') ) | trim }}"
32+
__update_etc_hosts_comment: "{{ (thishost.node_comment | d('') + ' ' + thishost.hana_site | d('')) | trim }}"
3333
__update_etc_hosts_alias_mode: "{{ thishost.alias_mode | default('merge') }}"
3434

3535
- name: Prepend Hashtag to comment
3636
when: __update_etc_hosts_comment|length > 0
3737
ansible.builtin.set_fact:
3838
__update_etc_hosts_comment: "# {{ __update_etc_hosts_comment }}"
3939

40-
- name: merge existing aliases with new alis list
40+
- name: Merge existing aliases with new alis list
4141
when: __update_etc_hosts_alias_mode != "overwrite"
4242
block:
4343
- name: Get all existing hostname aliases of {{ thishost.node_ip }}
@@ -52,12 +52,12 @@
5252
changed_when: false
5353
- name: Add defined aliases
5454
ansible.builtin.set_fact:
55-
__update_etc_hosts_aliases: "{{ (__update_etc_hosts_register_aliases.stdout.split(' ') + thishost.aliases|d([]))|unique|join(' ') }}"
55+
__update_etc_hosts_aliases: "{{ (__update_etc_hosts_register_aliases.stdout.split(' ') + thishost.aliases | d([])) | unique | join(' ') }}"
5656

5757
- name: Overwrite existing aliases
5858
when: __update_etc_hosts_alias_mode == "overwrite"
5959
ansible.builtin.set_fact:
60-
__update_etc_hosts_aliases: "{{ thishost.node_aliases|d([])|unique|join(' ') }}"
60+
__update_etc_hosts_aliases: "{{ thishost.node_aliases | d([]) | unique | join(' ') }}"
6161

6262
- name: Display host and domain name, and IP address before the modification
6363
ansible.builtin.debug:
@@ -90,7 +90,7 @@
9090
- "More than one line containing {{ thishost.node_ip }}. File {{ __update_etc_hosts_file }} will not be modified."
9191
when:
9292
- not ansible_check_mode
93-
- __update_etc_hosts_register_duplicate_ip_check.stdout == 'Duplicate IP entry in {{ __update_etc_hosts_file }}!'
93+
- __update_etc_hosts_register_duplicate_ip_check.rc == 1
9494

9595
- name: Ensure that the entry in hosts file is correct
9696
ansible.builtin.lineinfile:
@@ -100,7 +100,7 @@
100100
backup: true
101101
when:
102102
- not ansible_check_mode
103-
- __update_etc_hosts_register_duplicate_ip_check.stdout != 'Duplicate IP entry in {{ __update_etc_hosts_file }}!'
103+
- __update_etc_hosts_register_duplicate_ip_check.rc == 0
104104

105105
- name: Check for duplicate or missing entries of hostname and fqdn in {{ __update_etc_hosts_file }}
106106
ansible.builtin.shell: |

0 commit comments

Comments
 (0)