forked from sap-linuxlab/community.sap_install
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.yml
More file actions
80 lines (73 loc) · 3.27 KB
/
Copy pathmain.yml
File metadata and controls
80 lines (73 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# SPDX-License-Identifier: Apache-2.0
---
# tasks file for sap_maintain_etc_hosts
#- name: Double check that list entries with state present do not have duplicate IP addresses
# ansible.builtin.assert:
# that:
# - sap_maintain_etc_hosts_list | selectattr('state')
- name: Get list of hosts to be added with no state definition
ansible.builtin.set_fact:
__sap_maintain_etc_hosts_present: "{{ sap_maintain_etc_hosts_list | selectattr('state', 'undefined') | list }}"
when: sap_maintain_etc_hosts_list is defined
- name: Add list of hosts with state=present
ansible.builtin.set_fact:
__sap_maintain_etc_hosts_present: "{{ __sap_maintain_etc_hosts_present +
(sap_maintain_etc_hosts_list | difference(__sap_maintain_etc_hosts_present) | selectattr('state', 'eq', 'present') | list) }}"
- name: Debug list of hosts to be present
ansible.builtin.debug:
msg:
- "{{ __sap_maintain_etc_hosts_present }}"
verbosity: 2
when:
- __sap_maintain_etc_hosts_present is defined
- name: Ensure no duplicate IPs are in the list for adding to hosts
ansible.builtin.assert:
that:
(__sap_maintain_etc_hosts_present | map(attribute='node_ip') | length) ==
(__sap_maintain_etc_hosts_present | map(attribute='node_ip') | unique | length)
msg: "You have defined duplicate ip addresses to be created!"
when:
- __sap_maintain_etc_hosts_present is defined
- name: Ensure no duplicate hostnames are in the list for adding to hosts
ansible.builtin.assert:
that:
(__sap_maintain_etc_hosts_present | map(attribute='node_name') | length) ==
(__sap_maintain_etc_hosts_present | map(attribute='node_name') | unique | length)
msg: "You have defined duplicate hostnames to be created!"
when:
- __sap_maintain_etc_hosts_present is defined
- name: Ensure required defaults are read from setup module
when: >
not ((ansible_facts['hostname'] is defined) and
(ansible_facts['domain'] is defined) and
(ansible_facts['default_ipv4'] is defined))
## this is equivalent to
# (ansible_facts['hostname'] is undefined) or
# (ansible_facts['domain'] is undefined) or
# (ansible_facts['default_ipv4'] is defined)
ansible.builtin.setup:
gather_subset: "{{ __sap_maintain_etc_hosts_gather_subset }}"
filter:
- "ansible_facts['hostname']"
- "ansible_facts['domain']"
- "ansible_facts['default_ipv4']"
# when sap_maintain_etc_hosts_list is empty, set defaults for local host
- name: Ensure sap_maintain_etc_hosts_list is filled with defaults
when: >
( sap_maintain_etc_hosts_list is undefined) or
( sap_maintain_etc_hosts_list is none) or
( sap_maintain_etc_hosts_list | trim == '')
ansible.builtin.set_fact:
sap_maintain_etc_hosts_list:
- node_ip: "{{ ansible_facts['default_ipv4'].address }}"
node_name: "{{ ansible_facts['hostname'] }}"
node_domain: "{{ sap_domain | default(ansible_facts['domain']) }}"
node_comment: "managed by ansible sap_maintain_etc_hosts role"
state: present
- name: Add entry to "{{ __sap_maintain_etc_hosts_file }}"
loop: "{{ sap_maintain_etc_hosts_list }}"
loop_control:
label: "{{ thishost.node_name | d(thishost.node_ip) }}"
loop_var: thishost
ansible.builtin.include_tasks:
file: update_host_{{ thishost.state | default('present') }}.yml