Files
ansible/playbooks/time-region.yml
T
harwinder bec4eeb7c9 Refactor inventory into OS groups and update playbooks accordingly
Group hosts by OS (ubuntu/rocky) in inventory, refactor playbooks to
use group-targeted plays instead of ansible_os_family conditionals,
add bot host, and add Docker volume backup playbook via rsync to storage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-16 17:31:29 -04:00

115 lines
2.7 KiB
YAML

---
- name: Configure timezone on all hosts
hosts: all
become: true
gather_facts: true
vars:
timezone_region: "America/New_York"
tasks:
- name: Copy timezone file
ansible.builtin.copy:
src: "/usr/share/zoneinfo/{{ timezone_region }}"
dest: /etc/localtime
remote_src: true
- name: Write /etc/timezone
ansible.builtin.copy:
dest: /etc/timezone
content: "{{ timezone_region }}\n"
- name: Disable NTP on Ubuntu LXC containers
hosts: ubuntu
become: true
tasks:
- name: Stop and mask timesyncd on LXC
ansible.builtin.systemd:
name: systemd-timesyncd
state: stopped
enabled: false
masked: true
when: ansible_virtualization_type == "lxc"
- name: Disable NTP on Rocky Linux LXC containers
hosts: rocky
become: true
tasks:
- name: Stop and mask chronyd on LXC
ansible.builtin.systemd:
name: chronyd
state: stopped
enabled: false
masked: true
when: ansible_virtualization_type == "lxc"
- name: Configure NTP on Ubuntu VMs
hosts: ubuntu
become: true
vars:
ntp_server: "time.google.com"
tasks:
- name: Configure timesyncd
ansible.builtin.lineinfile:
path: /etc/systemd/timesyncd.conf
regexp: '^#?NTP='
line: "NTP={{ ntp_server }}"
state: present
when: ansible_virtualization_type != "lxc"
notify: Restart timesyncd
handlers:
- name: Restart timesyncd
ansible.builtin.systemd:
name: systemd-timesyncd
state: restarted
enabled: true
- name: Configure NTP on Rocky Linux VMs
hosts: rocky
become: true
vars:
ntp_server: "time.google.com"
tasks:
- name: Disable default chrony pools
ansible.builtin.replace:
path: /etc/chrony.conf
regexp: '^(pool|server) .*'
replace: '# \1 removed by Ansible'
when: ansible_virtualization_type != "lxc"
- name: Configure chrony NTP server
ansible.builtin.lineinfile:
path: /etc/chrony.conf
line: "server {{ ntp_server }} iburst"
insertafter: EOF
state: present
when: ansible_virtualization_type != "lxc"
notify: Restart chronyd
handlers:
- name: Restart chronyd
ansible.builtin.systemd:
name: chronyd
state: restarted
enabled: true
- name: Verify time configuration
hosts: all
become: true
tasks:
- name: Check current system time
ansible.builtin.command: date
register: check_time
changed_when: false
- name: Summary
ansible.builtin.debug:
msg: "{{ inventory_hostname }} ({{ ansible_virtualization_type | default('unknown') }}) - {{ check_time.stdout }}"