Compare commits

...

26 Commits

Author SHA1 Message Date
4b5e2352bc style 💎: Update time synchronization configuration
Updated the 'Configure Time Synchronization' task to use the new 'ntp' service instead of 'ntpd'. This change simplifies the configuration and improves consistency with other services.
2025-11-09 09:30:55 +01:00
14e11a40db chore 📦: Update ntp package to use ntpsec
Updated the Ansible playbook to install and configure ntpsec instead of traditional ntp, as recommended by Samba for secure timekeeping.
2025-11-07 18:07:16 +01:00
505271fcba fix 🐛: Fixed Ansible host check for 'not in' condition
Updated the failed_when condition to use a single quote instead of double quotes, ensuring correct comparison with the addc_ansible_host variable.
2025-11-07 06:31:45 +01:00
6107513f72 docs 📝: Update package list for smbclient and samba-client
Updated package lists to ensure compatibility with different Linux distributions. This change will improve the reliability of the Ansible playbook when using these packages.
2025-11-07 06:18:33 +01:00
4c18590881 refactor ♻️: Update package installation for python3-pip and pexpect
Updated package installation to use apt instead of pip, adding optional dependency on python3-pip. Also updated the become flag for pip and expect tasks.
2025-11-07 06:06:15 +01:00
a6bdc70932 chore 📦: Update Ansible playbook to include pip and pexpect dependencies
Added python3-pip and pexpect dependencies to the Ansible playbook to ensure proper installation of required tools for reverse DNS zone creation.
2025-11-07 05:58:27 +01:00
47cdaee59c style 💎: Update package installation order
Reordered package installations to ensure correct dependency resolution
2025-11-07 05:49:23 +01:00
af20d1dd86 chore 📦: Update dependencies in install.yml and verify.yml
Updated the `apt` module to use the latest version of pexpect, and updated the `community.general.expect` module to use the `ansible.builtin.expect` module. This change ensures that the Ansible playbook uses the most recent versions of the required packages and modules.
2025-11-06 20:29:19 +01:00
809be488f2 refactor ♻️: Improve Ansible expect module usage for Samba DNS operations
Updated the Ansible expect modules from 'ansible.builtin.expect' to 'community.general.expect' to improve readability and maintainability. This change ensures consistent usage of the community.general module, making it easier to manage and update the playbook in the future.
2025-11-06 19:41:47 +01:00
e9b75e9972 chore 📦: Update task dependencies and formatting
Updated the tasks/main.yml file to reflect changes in dependency ordering and code style. This change ensures consistency across the build process.
2025-11-06 19:12:44 +01:00
c30201da11 style 💎: Update Samba AD DC tasks for better readability and consistency
Refactored the main.yml file to improve organization and clarity. Renamed some tasks to follow a more consistent naming convention, making it easier to understand the flow of the setup process.
2025-11-06 19:10:13 +01:00
51a15d5e04 refactor ♻️: Improve Ansible expect module usage for samba-tool commands
Updated the community.general.expect and ansible.builtin.expect modules to use the correct Ansible modules, improving code readability and maintainability. This change ensures that the expected output is properly handled and reduces the risk of errors.
2025-11-06 19:03:18 +01:00
8d740e77a6 style 💎: Update Samba configuration for reverse DNS zone creation and verification
This commit updates the Samba configuration to create and verify a reverse DNS zone, PTR record, and Kerberos authentication. The changes include updating debug messages and adding new tasks to verify the setup.
2025-11-06 18:52:58 +01:00
6a926da12a style 💎: Update debug message for reverse DNS zone creation
Updated the debug message to include all required variables, ensuring accurate output and improved readability.
2025-11-06 18:37:12 +01:00
b6eb405236 docs 📝: Update verify.yml documentation for reverse DNS zone creation
Updated the 'name' section of the verify.yml file to include a comment explaining the purpose of creating the reverse DNS zone, making it easier to understand and maintain.
2025-11-06 18:14:38 +01:00
7fdf0e95e3 docs 📝: Update verify.yml documentation for reverse DNS zone creation
Updated the 'name' field in the 'tasks/verify.yml' file to include quotes around the variable {{ addc_reverse_zone_name }} for proper formatting. This change ensures consistent and readable documentation.
2025-11-06 18:06:57 +01:00
3b08c991cd docs 📝: Update verify.yml documentation
Updated the 'create reverse dns zone' task with correct quotes around variable names, ensuring proper formatting and readability of the Ansible playbook.
2025-11-06 17:37:10 +01:00
8e7a4e4b5d style 💎: Update kerberos copy task to use remote source
Changed the `copy` task in kerberos.yml to use a remote source for the krb5 configuration file, allowing for easier management of the file on remote hosts.
2025-11-06 17:24:16 +01:00
82dc88e827 style 💎: Fix regex pattern in kerberos.yml
Updated regular expression to correctly extract krb5.conf path, ensuring accurate output from samba_provision command.
2025-11-06 17:13:54 +01:00
8c3adc6cf9 style 💎: Update Samba provision output path
Updated the default path for the Samba provision output to /var/lib/samba/private/krb5.conf, ensuring consistency with the expected location.
2025-11-06 17:13:16 +01:00
e0389aae85 style 💎: Improve regex pattern for parsing samba provision output
Updated the regex pattern to correctly extract private/krb5.conf paths from the samba provision output, ensuring accurate configuration file detection.
2025-11-06 06:48:46 +01:00
b4408b2dfe refactor ♻️: Improve regex pattern matching for kerberos configuration
Updated regular expressions in the `kerberos.yml` file to correctly extract and format Kerberos configuration paths, ensuring consistency and accuracy in the Ansible playbook.
2025-11-06 06:37:23 +01:00
7f560f7653 refactor ♻️: Improve Kerberos configuration validation and extraction
Updated the Ansible playbook to validate the presence of the krb5.conf file, extract its path, and display it in a debug message. Additionally, added checks for the file's existence on disk and its contents to ensure proper Kerberos configuration.
2025-11-06 06:30:35 +01:00
2b97e9b61b refactor ♻️: Improve regex pattern for extracting krb5 conf path
Updated the regular expression to correctly extract the absolute path of the krb5.conf file from the samba provision output, removing unnecessary quotes and commas.
2025-11-06 06:18:18 +01:00
89e5606a4a Merge branch 'main' of https://repo.piave7.duckdns.org/Jose/samba-ad-dc 2025-11-06 06:13:44 +01:00
43f0ef58e7 style 💎: Improve regex pattern for extracting krb5 conf path
Updated the regular expression to correctly extract the absolute path of the krb5.conf file from the samba provision output. This change ensures that the extracted path is properly formatted and can be used in subsequent tasks.
2025-11-06 06:13:41 +01:00
6 changed files with 88 additions and 42 deletions

View File

@@ -45,6 +45,8 @@ samba_packages:
- python3-setproctitle
# - smbclient
- samba-ad-dc
- smbclient # Debian/Ubuntu
- samba-client # RHEL family (it will skip if not available)
# template for /etc/resolv.conf
location_internal_dns: 192.168.1.1

View File

@@ -1,9 +1,14 @@
---
# - name: Install pexpect # required for verify.yml
# ansible.builtin.apt:
# pkg: pexpect
# state: latest
- name: Install required packages
ansible.builtin.apt:
pkg: '{{ samba_packages }}'
state: latest
update_cache: yes
# update_cache: yes
autoclean: yes
autoremove: yes
purge: true

View File

@@ -2,23 +2,47 @@
- name: Extract absolute krb5.conf path from provision output
ansible.builtin.set_fact:
krb5_conf_path: >-
{{ (
{{
(
samba_provision_output.stdout
| regex_findall("(/[^\\s,'\"]+krb5\\.conf)")
| regex_findall('(/[^\\s,"'']*/private/krb5\\.conf)')
| list
| default([])
)
| first
| default('')
) | replace(\"'\", '') | replace('\"', '') | replace(',', '') | trim }}
| default('/var/lib/samba/private/krb5.conf')
| trim
}}
when: samba_provision_output.stdout is defined
# the regex doesnt actually work
- name: print krb5.conf path
- name: Show extracted krb5.conf path
ansible.builtin.debug:
msg: "Krb5.conf path: {{ krb5_conf_path }}"
msg: "Extracted krb5.conf path: {{ krb5_conf_path | default('N/A') }}"
- name: Check if krb5.conf exists on disk
ansible.builtin.stat:
path: "{{ krb5_conf_path }}"
register: krb5_conf_stat
when: krb5_conf_path != ''
- name: Validate krb5.conf presence
ansible.builtin.fail:
msg: "Kerberos configuration file was not found at {{ krb5_conf_path }}. Provision may have failed."
when:
- krb5_conf_path != ''
- not krb5_conf_stat.stat.exists | default(false)
- name: Confirm Kerberos configuration found
ansible.builtin.debug:
msg: "Kerberos configuration verified: {{ krb5_conf_path }}"
when: krb5_conf_stat.stat.exists | default(false)
- name: Copy krb5.conf to /etc/krb5.conf
ansible.builtin.copy:
src: '{{ krb5_conf_path }}'
dest: /etc/krb5.conf
remote_src: true
owner: root
group: root
mode: '0644'

View File

@@ -17,6 +17,6 @@
- name: Testing Samba AD DC
include_tasks: verify.yml
- name: Configure Time Synchronization
include_tasks: ntpd.yml
# - name: Configure Time Synchronization
# include_tasks: ntpd.yml

View File

@@ -1,7 +1,7 @@
---
- name: Ensure the ntp package is installed
ansible.builtin.package:
name: ntp
ansible.builtin.apt:
name: ntpsec
state: present
- name: Search common Samba locations for the 'ntp_signd' directory

View File

@@ -1,21 +1,36 @@
---
- name: Start the samba service
- name: "Start the samba service"
ansible.builtin.service:
name: samba
state: started
enabled: true
- name: Create the reverse DNS zone {{ addc_reverse_zone_name }}
community.general.expect:
# Note: The 'expect' module is in the 'community.general' collection
command: 'samba-tool dns zonecreate {{ addc_ansible_host }} {{ addc_reverse_zone_name }} -U Administrator'
- name: "Show key variables"
ansible.builtin.debug:
msg: "{{ addc_reverse_zone_name }} {{ addc_ansible_host }} {{ addc_admin_password }} {{ addc_ip_last_octet }} {{ addc_hostname }} {{ addc_auth_domain }}"
# - name: Ensure python3-pip is installed (optional)
# ansible.builtin.apt:
# name: python3-pip
# state: present
# become: true
- name: Ensure pexpect is installed (via apt)
ansible.builtin.apt:
name: python3-pexpect
state: present
become: true
- name: "Create the reverse DNS zone {{ addc_reverse_zone_name }}"
ansible.builtin.expect:
command: "samba-tool dns zonecreate {{ addc_ansible_host }} {{ addc_reverse_zone_name }} -U Administrator"
responses:
# Use the '(?i)' flag for case-insensitive matching of the prompt.
'(?i)password for.*:': '{{ addc_admin_password }}'
'(?i)password for.*:': "{{ addc_admin_password }}"
no_log: true # Highly recommended to prevent the password from appearing in logs
- name: Create the PTR (reverse) DNS record
community.general.expect:
- name: "Create the PTR (reverse) DNS record"
ansible.builtin.expect:
# Command syntax: samba-tool dns add <server> <zone> <record_name> PTR <target_fqdn>
command: >
samba-tool dns add {{ addc_ansible_host }}
@@ -25,102 +40,102 @@
-U Administrator
responses:
# Expects the standard Samba password prompt
'(?i)password for.*:': '{{ addc_admin_password }}'
'(?i)password for.*:': "{{ addc_admin_password }}"
no_log: true # Hide sensitive data from logs
- name: Verify Samba file server by listing local shares
- name: "Verify Samba file server by listing local shares"
ansible.builtin.command: smbclient -L localhost -N
register: smbclient_output
changed_when: false # This is a verification step, it doesn't change the host state
- name: Report the results of the smbclient verification
- name: "Report the results of the smbclient verification"
ansible.builtin.debug:
msg: 'Samba Shares found: {{ smbclient_output.stdout }}'
- name: Verify Samba AD authentication by accessing the netlogon share
community.general.expect:
- name: "Verify Samba AD authentication by accessing the netlogon share"
ansible.builtin.expect:
# Command to run: smbclient //localhost/netlogon -UAdministrator -c 'ls'
# The -c 'ls' command lists files on the share.
command: smbclient //localhost/netlogon -UAdministrator -c 'ls'
responses:
# Use the (?i) flag for case-insensitive matching of the prompt.
'(?i)password:': '{{ addc_admin_password }}'
'(?i)password for.*:': "{{ addc_admin_password }}"
no_log: true # CRITICAL: Prevents the password from being logged
register: auth_verification
changed_when: false # This is a verification/check, not a change
- name: Verify LDAP Service Record (SRV _ldap._tcp)
- name: "Verify LDAP Service Record (SRV _ldap._tcp)"
ansible.builtin.command: host -t SRV _ldap._tcp.{{ addc_auth_domain | lower }}.
register: ldap_srv_check
changed_when: false
failed_when: "'has SRV record' not in ldap_srv_check.stdout"
- name: Debug - Show LDAP SRV check result
- name: "Debug - Show LDAP SRV check result"
ansible.builtin.debug:
var: ldap_srv_check.stdout
- name: Verify Kerberos Service Record (SRV _kerberos._udp)
- name: "Verify Kerberos Service Record (SRV _kerberos._udp)"
ansible.builtin.command: host -t SRV _kerberos._udp.{{ addc_auth_domain | lower }}.
register: kerberos_srv_check
changed_when: false
failed_when: "'has SRV record' not in kerberos_srv_check.stdout"
- name: Debug - Show Kerberos SRV check result
- name: "Debug - Show Kerberos SRV check result"
ansible.builtin.debug:
var: kerberos_srv_check.stdout
- name: Verify DC's A (Forward) Record
- name: "Verify DC's A (Forward) Record"
ansible.builtin.command: host -t A {{ addc_hostname | lower }}.{{ addc_auth_domain | lower }}.
register: a_record_check
changed_when: false
failed_when: '{{ addc_ansible_host }} not in a_record_check.stdout'
failed_when: "'{{ addc_ansible_host }}' not in a_record_check.stdout"
- name: Debug - Show A Record check result
- name: "Debug - Show A Record check result"
ansible.builtin.debug:
var: a_record_check.stdout
- name: Verify DC's PTR (Reverse) Record
- name: "Verify DC's PTR (Reverse) Record"
ansible.builtin.command: host -t PTR {{ addc_ansible_host }}
register: ptr_record_check
changed_when: false
# Assuming dc1.{{ addc_auth_domain }} is the expected output for the reverse record
failed_when: "'domain name pointer {{ addc_hostname | lower }}.{{ addc_auth_domain | lower }}' not in ptr_record_check.stdout"
- name: Debug - Show PTR Record check result
- name: "Debug - Show PTR Record check result"
ansible.builtin.debug:
var: ptr_record_check.stdout
- name: Verify Kerberos authentication using kinit
community.general.expect:
- name: "Verify Kerberos authentication using kinit"
ansible.builtin.expect:
# Command to run: kinit administrator
command: kinit administrator
responses:
# Expects the standard Kerberos password prompt
# The (?i) flag ensures case-insensitive matching.
'(?i)password for administrator.*:': '{{ addc_admin_password }}'
'(?i)password for administrator.*:': "{{ addc_admin_password }}"
no_log: true # CRITICAL: Prevents the password from being logged
register: kinit_check
changed_when: false # This is a verification/check, not a change
- name: Debug - Show kinit verification result (should be empty on success)
- name: "Debug - Show kinit verification result (should be empty on success)"
ansible.builtin.debug:
msg: 'Kerberos kinit verification successful. Output: {{ kinit_check.stdout }}'
- name: Optional - Show the cached Kerberos ticket
- name: "Optional - Show the cached Kerberos ticket"
ansible.builtin.command: klist
register: klist_output
changed_when: false
when: kinit_check is succeeded
- name: Debug - Show klist output
- name: "Debug - Show klist output"
ansible.builtin.debug:
var: klist_output.stdout
when: klist_check is defined
when: klist_output is defined