-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipaclient1
87 lines (73 loc) · 2.47 KB
/
ipaclient1
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
81
82
83
84
85
86
87
---
- name: Ensure IPA Client is Configured
hosts: ipaclients
become: true
vars:
desired_domain: lnx.foo.lan
ipa_domain: "{{ desired_domain }}"
ipaclient_no_ntp: true
ansible_python_interpreter: /usr/bin/python3
chrony_servers:
- 10.10.240.1
- 10.10.240.2
tasks:
- name: Check DNS record using community.dns.lookup
set_fact:
dns_record: "{{ lookup('community.dns.lookup', ansible_hostname + '.' + ipa_domain) | default([]) | first }}"
ignore_errors: true
- name: Debug - Show DNS record result
debug:
var: dns_record
- name: Get current DNS domain
set_fact:
current_domain: "{{ dns_record | default('') | regex_replace('.*\\.(.*)\\..*$', '\\1') | lower | default('') }}"
- name: Debug - Show current DNS domain
debug:
var: current_domain
- name: Prompt to change hostname if needed
when: dns_record is not defined or dns_record | default([]) == [] or current_domain != ipa_domain
block:
- name: Prompt to change hostname
ansible.builtin.pause:
prompt: "Hostname does not have a DNS record or the domain does not match lnx.corp.lan. Do you want to change it? (y/n)"
register: change_hostname
- name: Debug - Show user input after prompt
debug:
var: change_hostname.user_input
- name: Change hostname if user agrees
command: hostnamectl set-hostname "{{ ansible_hostname }}.{{ desired_domain }}"
when: change_hostname.user_input | lower == 'y'
check_mode: no
- name: Include IPA Client role
include_role:
name: ipaclient
- name: Install chrony
ansible.builtin.package:
name: chrony
state: present
- name: Configure chrony servers
ansible.builtin.lineinfile:
path: /etc/chrony.conf
line: "server {{ item }} iburst"
with_items: "{{ chrony_servers }}"
notify: restart chrony
- name: Install autofs
ansible.builtin.package:
name: autofs
state: present
- name: Configure autofs
ansible.builtin.copy:
content: |
/net -hosts
/misc /etc/auto.misc
dest: /etc/auto.master
notify: restart autofs
handlers:
- name: restart chrony
ansible.builtin.service:
name: chrony
state: restarted
- name: restart autofs
ansible.builtin.service:
name: autofs
state: restarted