Primi passaggi di correzione; playbook ancora da testare.
This commit is contained in:
commit
a8529d4f72
6 changed files with 88 additions and 0 deletions
2
ansible.cfg
Normal file
2
ansible.cfg
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[defaults]
|
||||||
|
inventory = hosts
|
8
deploy.yml
Normal file
8
deploy.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
vars_files:
|
||||||
|
- deploy_vars.yml
|
||||||
|
roles:
|
||||||
|
- fqdn
|
||||||
|
become: true
|
||||||
|
become_user: root
|
5
deploy_vars.yml
Normal file
5
deploy_vars.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
netbios: TEST
|
||||||
|
realm: TEST.LCL
|
||||||
|
domain: test.lcl
|
||||||
|
domainadmin: administrator
|
2
hosts
Normal file
2
hosts
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#localhost ansible_connection=local
|
||||||
|
zorin ansible_hostname=192.168.33.243 ansible_user=utente
|
49
roles/domsearch/tasks/main.yml
Normal file
49
roles/domsearch/tasks/main.yml
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
---
|
||||||
|
# Sistemiamo la ricerca per dominio, che potrebbe essere a ramengo.
|
||||||
|
|
||||||
|
- name: Individuiamo l'interfaccia di rete nativa
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
nic: "{{ ansible_default_ipv4.interface }}"
|
||||||
|
|
||||||
|
- name: Identifichiamo il profilo di connessione di NetworkManager
|
||||||
|
ansible.builtin.shell: >-
|
||||||
|
set -o pipefail;
|
||||||
|
nmcli connection | awk -F" " "/{{ nic }}/ { print $1 }'
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
|
register: nm_connection
|
||||||
|
|
||||||
|
- name: Forziamo il dominio di ricerca sulla connessione
|
||||||
|
ansible.builtin.command: >-
|
||||||
|
nmcli connection modify "{{ nm_connection.stdout|trim }}"
|
||||||
|
ipv4.dns-search {{ domain }}
|
||||||
|
|
||||||
|
- name: Forziamo temporaneamente per questa sessione il dominio di ricerca
|
||||||
|
ansible.builtin.command: >-
|
||||||
|
resolvectl domain {{ nic }} {{ domain }}
|
||||||
|
|
||||||
|
# Assumiamo che il server DNS inserito risolva il dominio.
|
||||||
|
# Consultiamo il DNS per ricevere informazioni sul domain controller.
|
||||||
|
|
||||||
|
- name: Determiniamo il nome del domain controller
|
||||||
|
ansible.builtin.shell: >-
|
||||||
|
set -o pipeline;
|
||||||
|
dig +short _ldap._tcp.{{ domain }} SRV | cut -d' ' -f 4 | sed -e 's/\.$//'
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
|
register: dcname
|
||||||
|
|
||||||
|
- name: Determiniamo l'IP del domain controller
|
||||||
|
ansible.builtin.command: dig +short {{ dcname.stdout | trim }}.
|
||||||
|
register: dcipaddr
|
||||||
|
|
||||||
|
- name: Impostiamo qualche fact
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
dc.name: "{{ dcname.stdout | trim }}"
|
||||||
|
dc.shortname: "{{ dc.name.split('.')[0] }}"
|
||||||
|
dc.ipaddr: "{{ dcipaddr | trim }}"
|
||||||
|
|
||||||
|
- name: Verifichiamo che il PC effettivamente risolva gli shortname
|
||||||
|
ansible.builtin.command: dig +short {{ dc.shortname }}
|
||||||
|
register: check_shortnames
|
||||||
|
failed_when: check_shortnames.stdout|trim != {{ dc.ipaddr }}
|
22
roles/fqdn/tasks/main.yml
Normal file
22
roles/fqdn/tasks/main.yml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
---
|
||||||
|
# Sistemiamo un po' di impostazioni legate al dominio
|
||||||
|
|
||||||
|
- name: Impostazione del dominio
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /etc/domainname
|
||||||
|
content: |
|
||||||
|
{{ domain }}
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0644'
|
||||||
|
|
||||||
|
- name: Sistemiamo il file hosts
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
line: "127.0.1.1\t{{ ansible_hostname }}.{{ domain }}\t{{ ansible_hostname }}"
|
||||||
|
regexp: "^127.0.1.1"
|
||||||
|
path: /etc/hosts
|
||||||
|
|
||||||
|
- name: Verifichiamo che tutto sia in ordine
|
||||||
|
ansible.builtin.command: hostname -f
|
||||||
|
register: returned_fqdn
|
||||||
|
failed_when: returned_fqdn.stdout != "{{ ansible_hostname }}.{{ domain }}"
|
Loading…
Add table
Add a link
Reference in a new issue